mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-09 18:28:08 +08:00
bitswap: test canceling subscription context after shutting down
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
parent
53958266d6
commit
2baa3312d1
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user