bitswap: test canceling subscription context after shutting down
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Feb 9, 2018 at 17:33 UTC
2baa3312d195089c74eac1531f4126d2d67494b4
1 file changed
+19
exchange/bitswap/notifications/notifications_test.go
+19
@@ -100,6 +100,25 @@ func TestDuplicateSubscribe(t *testing.T) {
100
assertBlocksEqual(t, e1, r2)
101
}
102
103
+func TestShutdownBeforeUnsubscribe(t *testing.T) {
104
+ e1 := blocks.NewBlock([]byte("1"))
105
+
106
+ n := New()
107
+ ctx, cancel := context.WithCancel(context.Background())
108
+ ch := n.Subscribe(ctx, e1.Cid()) // no keys provided
109
+ n.Shutdown()
110
+ cancel()
111
+
112
+ select {
113
+ case _, ok := <-ch:
114
+ if ok {
115
+ t.Fatal("channel should have been closed")
116
+ }
117
+ default:
118
+ t.Fatal("channel should have been closed")
119
+ }
120
+}
121
+
122
func TestSubscribeIsANoopWhenCalledWithNoKeys(t *testing.T) {
123
n := New()
124
defer n.Shutdown()