@cryptotaxi247 / kubo / commits / d8f9f5249

add a test to make sure duplicate subscriptions to the same block dont have weird side effects

Jeromy committed Feb 17, 2015 at 06:38 UTC d8f9f52498b064001d1f717d36bb5a055e6dd21d
1 file changed +24
exchange/bitswap/notifications/notifications_test.go
+24
@@ -76,6 +76,30 @@ func TestSubscribeMany(t *testing.T) {
76 assertBlocksEqual(t, e2, r2)
77 }
78
79 +// TestDuplicateSubscribe tests a scenario where a given block
80 +// would be requested twice at the same time.
81 +func TestDuplicateSubscribe(t *testing.T) {
82 + e1 := blocks.NewBlock([]byte("1"))
83 +
84 + n := New()
85 + defer n.Shutdown()
86 + ch1 := n.Subscribe(context.Background(), e1.Key())
87 + ch2 := n.Subscribe(context.Background(), e1.Key())
88 +
89 + n.Publish(e1)
90 + r1, ok := <-ch1
91 + if !ok {
92 + t.Fatal("didn't receive first expected block")
93 + }
94 + assertBlocksEqual(t, e1, r1)
95 +
96 + r2, ok := <-ch2
97 + if !ok {
98 + t.Fatal("didn't receive second expected block")
99 + }
100 + assertBlocksEqual(t, e1, r2)
101 +}
102 +
103 func TestSubscribeIsANoopWhenCalledWithNoKeys(t *testing.T) {
104 n := New()
105 defer n.Shutdown()