From ab65a1849c9e9ccaa760c2a85ded065fbd1bbb43 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 9 Feb 2018 17:33:57 -0800 Subject: [PATCH] bitswap: test canceling subscription context after shutting down License: MIT Signed-off-by: Steven Allen --- notifications/notifications_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/notifications/notifications_test.go b/notifications/notifications_test.go index 0377c30..a70a075 100644 --- a/notifications/notifications_test.go +++ b/notifications/notifications_test.go @@ -100,6 +100,25 @@ func TestDuplicateSubscribe(t *testing.T) { assertBlocksEqual(t, e1, r2) } +func TestShutdownBeforeUnsubscribe(t *testing.T) { + e1 := blocks.NewBlock([]byte("1")) + + n := New() + ctx, cancel := context.WithCancel(context.Background()) + ch := n.Subscribe(ctx, e1.Cid()) // no keys provided + n.Shutdown() + cancel() + + select { + case _, ok := <-ch: + if ok { + t.Fatal("channel should have been closed") + } + default: + t.Fatal("channel should have been closed") + } +} + func TestSubscribeIsANoopWhenCalledWithNoKeys(t *testing.T) { n := New() defer n.Shutdown() -- GitLab