From 856a25c8eb7b740a135d48e78cf0fac41360592c Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 13 Jan 2018 20:52:38 +0200 Subject: [PATCH] WithMaxConcurrency is WithValidatorConcurrency and defaultMaxConcurrency is defaultValidateConcurrency. --- floodsub.go | 10 +++++----- floodsub_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/floodsub.go b/floodsub.go index 627a863..f32dbf4 100644 --- a/floodsub.go +++ b/floodsub.go @@ -18,9 +18,9 @@ import ( ) const ( - ID = protocol.ID("/floodsub/1.0.0") - defaultMaxConcurrency = 10 - defaultValidateTimeout = 150 * time.Millisecond + ID = protocol.ID("/floodsub/1.0.0") + defaultValidateConcurrency = 10 + defaultValidateTimeout = 150 * time.Millisecond ) var log = logging.Logger("floodsub") @@ -521,7 +521,7 @@ func WithValidatorTimeout(timeout time.Duration) SubOpt { } } -func WithMaxConcurrency(n int) SubOpt { +func WithValidatorConcurrency(n int) SubOpt { return func(sub *Subscription) error { sub.validateThrottle = make(chan struct{}, n) return nil @@ -558,7 +558,7 @@ func (p *PubSub) SubscribeByTopicDescriptor(td *pb.TopicDescriptor, opts ...SubO } if sub.validate != nil && sub.validateThrottle == nil { - sub.validateThrottle = make(chan struct{}, defaultMaxConcurrency) + sub.validateThrottle = make(chan struct{}, defaultValidateConcurrency) } out := make(chan *Subscription, 1) diff --git a/floodsub_test.go b/floodsub_test.go index 351f584..6d58657 100644 --- a/floodsub_test.go +++ b/floodsub_test.go @@ -541,7 +541,7 @@ func TestValidateOverload(t *testing.T) { block := make(chan struct{}) sub, err := psubs[1].Subscribe(topic, - WithMaxConcurrency(tc.maxConcurrency), + WithValidatorConcurrency(tc.maxConcurrency), WithValidator(func(ctx context.Context, msg *Message) bool { <-block return true @@ -554,7 +554,7 @@ func TestValidateOverload(t *testing.T) { time.Sleep(time.Millisecond * 50) if len(tc.msgs) != tc.maxConcurrency+1 { - t.Fatalf("expected number of messages sent to be defaultMaxConcurrency+1. Got %d, expected %d", len(tc.msgs), tc.maxConcurrency+1) + t.Fatalf("expected number of messages sent to be maxConcurrency+1. Got %d, expected %d", len(tc.msgs), tc.maxConcurrency+1) } p := psubs[0]