From e1418b1ff730e8767f925013b531306437d84465 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 13 Jul 2015 09:05:47 -0700 Subject: [PATCH] Race test for pkg/pubsub package Signed-off-by: Alexander Morozov --- pubsub/publisher_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pubsub/publisher_test.go b/pubsub/publisher_test.go index 5e99e46..d6b0a1d 100644 --- a/pubsub/publisher_test.go +++ b/pubsub/publisher_test.go @@ -96,6 +96,26 @@ func newTestSubscriber(p *Publisher) *testSubscriber { return ts } +// for testing with -race +func TestPubSubRace(t *testing.T) { + p := NewPublisher(0, 1024) + var subs [](*testSubscriber) + for j := 0; j < 50; j++ { + subs = append(subs, newTestSubscriber(p)) + } + for j := 0; j < 1000; j++ { + p.Publish(sampleText) + } + time.AfterFunc(1*time.Second, func() { + for _, s := range subs { + p.Evict(s.dataCh) + } + }) + for _, s := range subs { + s.Wait() + } +} + func BenchmarkPubSub(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer()