From 2baa3312d195089c74eac1531f4126d2d67494b4 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/exchange/bitswap/notifications/notifications_test.go b/exchange/bitswap/notifications/notifications_test.go index 0377c307d..a70a0755a 100644 --- a/exchange/bitswap/notifications/notifications_test.go +++ b/exchange/bitswap/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()