@cryptotaxi247 / kubo / commits / 20382340f

test(bs/n) check for duplicates received

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Nov 21, 2014 at 18:48 UTC 20382340f58851bb46d59693003582e817f11bd3
1 file changed +27 -2
exchange/bitswap/notifications/notifications_test.go
+27 -2
@@ -9,6 +9,31 @@ import (
9 blocks "github.com/jbenet/go-ipfs/blocks"
10 )
11
12 +func TestDuplicates(t *testing.T) {
13 + b1 := blocks.NewBlock([]byte("1"))
14 + b2 := blocks.NewBlock([]byte("2"))
15 +
16 + n := New()
17 + defer n.Shutdown()
18 + ch := n.Subscribe(context.Background(), b1.Key(), b2.Key())
19 +
20 + n.Publish(b1)
21 + blockRecvd, ok := <-ch
22 + if !ok {
23 + t.Fail()
24 + }
25 + assertBlocksEqual(t, b1, blockRecvd)
26 +
27 + n.Publish(b1) // ignored duplicate
28 +
29 + n.Publish(b2)
30 + blockRecvd, ok = <-ch
31 + if !ok {
32 + t.Fail()
33 + }
34 + assertBlocksEqual(t, b2, blockRecvd)
35 +}
36 +
37 func TestPublishSubscribe(t *testing.T) {
38 blockSent := blocks.NewBlock([]byte("Greetings from The Interval"))
39
@@ -80,9 +105,9 @@ func assertBlockChannelNil(t *testing.T, blockChannel <-chan *blocks.Block) {
105
106 func assertBlocksEqual(t *testing.T, a, b *blocks.Block) {
107 if !bytes.Equal(a.Data, b.Data) {
83 - t.Fail()
108 + t.Fatal("blocks aren't equal")
109 }
110 if a.Key() != b.Key() {
86 - t.Fail()
111 + t.Fatal("block keys aren't equal")
112 }
113 }