@cryptotaxi247 / kubo / commits / 9f685af14

test(bitswap)

Brian Tiger Chow committed Sep 19, 2014 at 12:58 UTC 9f685af14fa067a4327e2154a613a2bf28f06359
1 file changed +31 -5
exchange/bitswap/bitswap_test.go
+31 -5
@@ -33,19 +33,45 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
33
34 net := LocalNetwork()
35 rs := newRoutingServer()
36 - ipfs := session(net, rs, []byte("peer id"))
37 - // ctx := context.Background()
38 - ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond)
39 - block := testutil.NewBlockOrFail(t, "block")
36
37 + block := testutil.NewBlockOrFail(t, "block")
38 rs.Announce(&peer.Peer{}, block.Key()) // but not on network
39
43 - _, err := ipfs.exchange.Block(ctx, block.Key())
40 + solo := session(net, rs, []byte("peer id"))
41 +
42 + ctx, _ := context.WithTimeout(context.Background(), time.Nanosecond)
43 + _, err := solo.exchange.Block(ctx, block.Key())
44 +
45 if err != context.DeadlineExceeded {
46 t.Fatal("Expected DeadlineExceeded error")
47 }
48 }
49
50 +// TestGetBlockAfterRequesting...
51 +
52 +func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
53 + t.Skip("Failing. Work in progress")
54 +
55 + net := LocalNetwork()
56 + rs := newRoutingServer()
57 + block := testutil.NewBlockOrFail(t, "block")
58 +
59 + hasBlock := session(net, rs, []byte("hasBlock"))
60 +
61 + rs.Announce(hasBlock.peer, block.Key())
62 + hasBlock.blockstore.Put(block)
63 + hasBlock.exchange.HasBlock(context.Background(), block)
64 +
65 + wantsBlock := session(net, rs, []byte("wantsBlock"))
66 +
67 + ctx, _ := context.WithTimeout(context.Background(), time.Second)
68 + _, err := wantsBlock.exchange.Block(ctx, block.Key())
69 + if err != nil {
70 + t.Log(err)
71 + t.Fatal("Expected to succeed")
72 + }
73 +}
74 +
75 type ipfs struct {
76 peer *peer.Peer
77 exchange exchange.Interface