Commit 6896d8f0 authored by Jeromy's avatar Jeromy

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

parent 55523af9
......@@ -76,6 +76,30 @@ func TestSubscribeMany(t *testing.T) {
assertBlocksEqual(t, e2, r2)
}
// TestDuplicateSubscribe tests a scenario where a given block
// would be requested twice at the same time.
func TestDuplicateSubscribe(t *testing.T) {
e1 := blocks.NewBlock([]byte("1"))
n := New()
defer n.Shutdown()
ch1 := n.Subscribe(context.Background(), e1.Key())
ch2 := n.Subscribe(context.Background(), e1.Key())
n.Publish(e1)
r1, ok := <-ch1
if !ok {
t.Fatal("didn't receive first expected block")
}
assertBlocksEqual(t, e1, r1)
r2, ok := <-ch2
if !ok {
t.Fatal("didn't receive second expected block")
}
assertBlocksEqual(t, e1, r2)
}
func TestSubscribeIsANoopWhenCalledWithNoKeys(t *testing.T) {
n := New()
defer n.Shutdown()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment