From 963fbdde63c98d4171d28dbed961c07c8259ffdd Mon Sep 17 00:00:00 2001 From: Andrew Bernat Date: Wed, 10 Apr 2019 22:41:08 -0700 Subject: [PATCH] add 2 extra tests - one to demonstrate combined subscriptions: sub, subOnce, subOnceEach - one to demonstrate pub will succeed w/o any subscriber --- pubsub_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pubsub_test.go b/pubsub_test.go index 7930704..d47c070 100644 --- a/pubsub_test.go +++ b/pubsub_test.go @@ -157,6 +157,30 @@ func TestMultiSubOnceEach(t *testing.T) { checkContents(t, ch, []string{"hi", "hello"}) } +func TestMultiSubCombined(t *testing.T) { + ps := New(6) + + ch1 := ps.Sub("t1", "t2") + ch2 := ps.SubOnce("t1", "t2") + ch3 := ps.SubOnceEach("t1", "t2") + + ps.Pub("hi1", "t1", "t2") + ps.Pub("hi2", "t1", "t2") + ps.Pub("hi3", "t1", "t2") + + ps.Shutdown() + + checkContents(t, ch1, []string{"hi1", "hi1", "hi2", "hi2", "hi3", "hi3"}) + checkContents(t, ch2, []string{"hi1"}) + checkContents(t, ch3, []string{"hi1", "hi1"}) +} + +func TestPubWithoutSub(t *testing.T) { + ps := New(1) + ps.Pub("hi", "t1") + ps.Shutdown() +} + func TestMultiPub(t *testing.T) { ps := New(2) ch1 := ps.Sub("t1")