From 0d619cfdf1cf75bc216538fe7959d5830b4e2036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9=20=D0=A2=D1=80?= =?UTF-8?q?=D0=B5=D1=82=D1=8C=D1=8F=D0=BA?= Date: Sun, 29 Mar 2020 09:48:02 +0000 Subject: [PATCH] closeWaitsMessageDeliver test --- pubsub/pubsub_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pubsub/pubsub_test.go b/pubsub/pubsub_test.go index e98a243..ddad448 100644 --- a/pubsub/pubsub_test.go +++ b/pubsub/pubsub_test.go @@ -313,6 +313,26 @@ func TestPubSub_close(t *testing.T) { } } +func TestPubSub_closeWaitsMessageDelivery(t *testing.T) { + p := NewPubSub() + + wg := sync.WaitGroup{} + + _, err := p.Subscribe("q", func(msg interface{}) { + time.Sleep(100*time.Millisecond) + wg.Done() + }) + require.NoError(t, err) + + for i := 0; i < 11; i++ { + wg.Add(1) + err = p.Publish("q", "pew-pew") + require.NoError(t, err) + } + checkedClose(t, p) + wg.Wait() +} + func checkedClose(t *testing.T, c interface { Close(ctx context.Context) error }) {