Skip to content

Commit ed7b99e

Browse files
committed
Tests: fix tests after changes of routing options
1 parent b64a8ae commit ed7b99e

File tree

17 files changed

+127
-100
lines changed

17 files changed

+127
-100
lines changed

bitswap/benchmarks_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import (
1212
"testing"
1313
"time"
1414

15-
blocks "github.com/ipfs/go-block-format"
16-
"github.com/ipfs/go-test/random"
17-
protocol "github.com/libp2p/go-libp2p/core/protocol"
18-
1915
"github.com/ipfs/boxo/bitswap"
2016
bsnet "github.com/ipfs/boxo/bitswap/network"
2117
testinstance "github.com/ipfs/boxo/bitswap/testinstance"
2218
tn "github.com/ipfs/boxo/bitswap/testnet"
19+
mockrouting "github.com/ipfs/boxo/routing/mock"
20+
blocks "github.com/ipfs/go-block-format"
2321
cid "github.com/ipfs/go-cid"
2422
delay "github.com/ipfs/go-ipfs-delay"
23+
"github.com/ipfs/go-test/random"
24+
protocol "github.com/libp2p/go-libp2p/core/protocol"
2525
)
2626

2727
type fetchFunc func(b *testing.B, bs *bitswap.Bitswap, ks []cid.Cid)
@@ -134,6 +134,7 @@ func BenchmarkFetchFromOldBitswap(b *testing.B) {
134134
benchmarkLog = nil
135135
fixedDelay := delay.Fixed(10 * time.Millisecond)
136136
bstoreLatency := time.Duration(0)
137+
router := mockrouting.NewServer()
137138

138139
for _, bch := range mixedBenches {
139140
b.Run(bch.name, func(b *testing.B) {
@@ -148,10 +149,10 @@ func BenchmarkFetchFromOldBitswap(b *testing.B) {
148149
oldProtocol := []protocol.ID{bsnet.ProtocolBitswapOneOne}
149150
oldNetOpts := []bsnet.NetOpt{bsnet.SupportedProtocols(oldProtocol)}
150151
oldBsOpts := []bitswap.Option{bitswap.SetSendDontHaves(false)}
151-
oldNodeGenerator := testinstance.NewTestInstanceGenerator(net, oldNetOpts, oldBsOpts)
152+
oldNodeGenerator := testinstance.NewTestInstanceGenerator(net, router, oldNetOpts, oldBsOpts)
152153

153154
// Regular new Bitswap node
154-
newNodeGenerator := testinstance.NewTestInstanceGenerator(net, nil, nil)
155+
newNodeGenerator := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
155156
var instances []testinstance.Instance
156157

157158
// Create new nodes (fetchers + seeds)
@@ -295,7 +296,8 @@ func BenchmarkDatacenterMultiLeechMultiSeed(b *testing.B) {
295296
for i := 0; i < b.N; i++ {
296297
net := tn.RateLimitedVirtualNetwork(d, rateLimitGenerator)
297298

298-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
299+
router := mockrouting.NewServer()
300+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
299301
defer ig.Close()
300302

301303
instances := ig.Instances(numnodes)
@@ -312,8 +314,8 @@ func BenchmarkDatacenterMultiLeechMultiSeed(b *testing.B) {
312314
func subtestDistributeAndFetch(b *testing.B, numnodes, numblks int, d delay.D, bstoreLatency time.Duration, df distFunc, ff fetchFunc) {
313315
for i := 0; i < b.N; i++ {
314316
net := tn.VirtualNetwork(d)
315-
316-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
317+
router := mockrouting.NewServer()
318+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
317319

318320
instances := ig.Instances(numnodes)
319321
rootBlock := random.BlocksOfSize(1, rootBlockSize)
@@ -327,8 +329,8 @@ func subtestDistributeAndFetch(b *testing.B, numnodes, numblks int, d delay.D, b
327329
func subtestDistributeAndFetchRateLimited(b *testing.B, numnodes, numblks int, d delay.D, rateLimitGenerator tn.RateLimitGenerator, blockSize int64, bstoreLatency time.Duration, df distFunc, ff fetchFunc) {
328330
for i := 0; i < b.N; i++ {
329331
net := tn.RateLimitedVirtualNetwork(d, rateLimitGenerator)
330-
331-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
332+
router := mockrouting.NewServer()
333+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
332334
defer ig.Close()
333335

334336
instances := ig.Instances(numnodes)

bitswap/bitswap_test.go

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/ipfs/boxo/bitswap/server"
1616
testinstance "github.com/ipfs/boxo/bitswap/testinstance"
1717
tn "github.com/ipfs/boxo/bitswap/testnet"
18+
mockrouting "github.com/ipfs/boxo/routing/mock"
1819
blocks "github.com/ipfs/go-block-format"
1920
cid "github.com/ipfs/go-cid"
2021
detectrace "github.com/ipfs/go-detect-race"
@@ -51,7 +52,8 @@ const kNetworkDelay = 0 * time.Millisecond
5152

5253
func TestClose(t *testing.T) {
5354
vnet := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
54-
ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil)
55+
router := mockrouting.NewServer()
56+
ig := testinstance.NewTestInstanceGenerator(vnet, router, nil, nil)
5557
defer ig.Close()
5658
block := random.BlocksOfSize(1, blockSize)[0]
5759
bitswap := ig.Next()
@@ -65,12 +67,13 @@ func TestClose(t *testing.T) {
6567

6668
func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
6769
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
68-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
70+
router := mockrouting.NewServer()
71+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
6972
defer ig.Close()
7073

7174
block := blocks.NewBlock([]byte("block"))
7275
pinfo := p2ptestutil.RandTestBogusIdentityOrFatal(t)
73-
err := ig.Routing().Client(pinfo).Provide(context.Background(), block.Cid(), true) // but not on network
76+
err := router.Client(pinfo).Provide(context.Background(), block.Cid(), true) // but not on network
7477
if err != nil {
7578
t.Fatal(err)
7679
}
@@ -90,7 +93,8 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
9093
func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
9194
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
9295
block := blocks.NewBlock([]byte("block"))
93-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
96+
router := mockrouting.NewServer()
97+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
9498
defer ig.Close()
9599

96100
peers := ig.Instances(2)
@@ -119,7 +123,8 @@ func TestDoesNotProvideWhenConfiguredNotTo(t *testing.T) {
119123
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
120124
block := blocks.NewBlock([]byte("block"))
121125
bsOpts := []bitswap.Option{bitswap.ProviderSearchDelay(50 * time.Millisecond)}
122-
ig := testinstance.NewTestInstanceGenerator(net, nil, bsOpts)
126+
router := mockrouting.NewServer()
127+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, bsOpts)
123128
defer ig.Close()
124129

125130
hasBlock := ig.Next()
@@ -153,7 +158,8 @@ func TestUnwantedBlockNotAdded(t *testing.T) {
153158
bsMessage := bsmsg.New(true)
154159
bsMessage.AddBlock(block)
155160

156-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
161+
router := mockrouting.NewServer()
162+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
157163
defer ig.Close()
158164

159165
peers := ig.Instances(2)
@@ -168,7 +174,7 @@ func TestUnwantedBlockNotAdded(t *testing.T) {
168174
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
169175
defer cancel()
170176

171-
doesNotWantBlock.Exchange.ReceiveMessage(ctx, hasBlock.Peer, bsMessage)
177+
doesNotWantBlock.Exchange.ReceiveMessage(ctx, hasBlock.Identity.ID(), bsMessage)
172178

173179
blockInStore, err := doesNotWantBlock.Blockstore().Has(ctx, block.Cid())
174180
if err != nil || blockInStore {
@@ -187,7 +193,8 @@ func TestPendingBlockAdded(t *testing.T) {
187193
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
188194
sessionBroadcastWantCapacity := 4
189195

190-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
196+
router := mockrouting.NewServer()
197+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
191198
defer ig.Close()
192199

193200
instance := ig.Instances(1)[0]
@@ -276,7 +283,8 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
276283
t.SkipNow()
277284
}
278285
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
279-
ig := testinstance.NewTestInstanceGenerator(net, nil, []bitswap.Option{
286+
router := mockrouting.NewServer()
287+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, []bitswap.Option{
280288
bitswap.TaskWorkerCount(5),
281289
bitswap.EngineTaskWorkerCount(5),
282290
bitswap.MaxOutstandingBytesPerPeer(1 << 20),
@@ -332,15 +340,16 @@ func TestSendToWantingPeer(t *testing.T) {
332340
}
333341

334342
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
335-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
343+
router := mockrouting.NewServer()
344+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
336345
defer ig.Close()
337346

338347
peers := ig.Instances(2)
339348
peerA := peers[0]
340349
peerB := peers[1]
341350

342-
t.Logf("Session %v\n", peerA.Peer)
343-
t.Logf("Session %v\n", peerB.Peer)
351+
t.Logf("Session %v\n", peerA.Identity.ID())
352+
t.Logf("Session %v\n", peerB.Identity.ID())
344353

345354
waitTime := time.Second * 5
346355

@@ -369,7 +378,8 @@ func TestSendToWantingPeer(t *testing.T) {
369378

370379
func TestEmptyKey(t *testing.T) {
371380
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
372-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
381+
router := mockrouting.NewServer()
382+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
373383
defer ig.Close()
374384
bs := ig.Instances(1)[0].Exchange
375385

@@ -402,7 +412,8 @@ func assertStat(t *testing.T, st *bitswap.Stat, sblks, rblks, sdata, rdata uint6
402412

403413
func TestBasicBitswap(t *testing.T) {
404414
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
405-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
415+
router := mockrouting.NewServer()
416+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
406417
defer ig.Close()
407418

408419
t.Log("Test a one node trying to get one block from another")
@@ -426,7 +437,7 @@ func TestBasicBitswap(t *testing.T) {
426437
// When second peer receives block, it should send out a cancel, so third
427438
// peer should no longer keep second peer's want
428439
if err = tu.WaitFor(ctx, func() error {
429-
if len(instances[2].Exchange.WantlistForPeer(instances[1].Peer)) != 0 {
440+
if len(instances[2].Exchange.WantlistForPeer(instances[1].Identity.ID())) != 0 {
430441
return errors.New("should have no items in other peers wantlist")
431442
}
432443
if len(instances[1].Exchange.GetWantlist()) != 0 {
@@ -473,7 +484,8 @@ func TestBasicBitswap(t *testing.T) {
473484

474485
func TestDoubleGet(t *testing.T) {
475486
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
476-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
487+
router := mockrouting.NewServer()
488+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
477489
defer ig.Close()
478490

479491
t.Log("Test a one node trying to get one block from another")
@@ -516,7 +528,7 @@ func TestDoubleGet(t *testing.T) {
516528
}
517529
t.Log(blk)
518530
case <-time.After(time.Second * 5):
519-
p1wl := instances[0].Exchange.WantlistForPeer(instances[1].Peer)
531+
p1wl := instances[0].Exchange.WantlistForPeer(instances[1].Identity.ID())
520532
if len(p1wl) != 1 {
521533
t.Logf("wantlist view didnt have 1 item (had %d)", len(p1wl))
522534
} else if !p1wl[0].Equals(blocks[0].Cid()) {
@@ -537,7 +549,8 @@ func TestDoubleGet(t *testing.T) {
537549

538550
func TestWantlistCleanup(t *testing.T) {
539551
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
540-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
552+
router := mockrouting.NewServer()
553+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
541554
defer ig.Close()
542555

543556
instances := ig.Instances(2)
@@ -658,7 +671,8 @@ func newReceipt(sent, recv, exchanged uint64) *server.Receipt {
658671

659672
func TestBitswapLedgerOneWay(t *testing.T) {
660673
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
661-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
674+
router := mockrouting.NewServer()
675+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
662676
defer ig.Close()
663677

664678
t.Log("Test ledgers match when one peer sends block to another")
@@ -674,8 +688,8 @@ func TestBitswapLedgerOneWay(t *testing.T) {
674688
t.Fatal(err)
675689
}
676690

677-
ra := instances[0].Exchange.LedgerForPeer(instances[1].Peer)
678-
rb := instances[1].Exchange.LedgerForPeer(instances[0].Peer)
691+
ra := instances[0].Exchange.LedgerForPeer(instances[1].Identity.ID())
692+
rb := instances[1].Exchange.LedgerForPeer(instances[0].Identity.ID())
679693

680694
// compare peer ledger receipts
681695
err = assertLedgerMatch(ra, rb)
@@ -706,7 +720,8 @@ func TestBitswapLedgerOneWay(t *testing.T) {
706720

707721
func TestBitswapLedgerTwoWay(t *testing.T) {
708722
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
709-
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
723+
router := mockrouting.NewServer()
724+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, nil)
710725
defer ig.Close()
711726

712727
t.Log("Test ledgers match when two peers send one block to each other")
@@ -730,8 +745,8 @@ func TestBitswapLedgerTwoWay(t *testing.T) {
730745
t.Fatal(err)
731746
}
732747

733-
ra := instances[0].Exchange.LedgerForPeer(instances[1].Peer)
734-
rb := instances[1].Exchange.LedgerForPeer(instances[0].Peer)
748+
ra := instances[0].Exchange.LedgerForPeer(instances[1].Identity.ID())
749+
rb := instances[1].Exchange.LedgerForPeer(instances[0].Identity.ID())
735750

736751
// compare peer ledger receipts
737752
err = assertLedgerMatch(ra, rb)
@@ -794,8 +809,9 @@ func (tsl *testingScoreLedger) Stop() {
794809
func TestWithScoreLedger(t *testing.T) {
795810
tsl := newTestingScoreLedger()
796811
net := tn.VirtualNetwork(delay.Fixed(kNetworkDelay))
812+
router := mockrouting.NewServer()
797813
bsOpts := []bitswap.Option{bitswap.WithScoreLedger(tsl)}
798-
ig := testinstance.NewTestInstanceGenerator(net, nil, bsOpts)
814+
ig := testinstance.NewTestInstanceGenerator(net, router, nil, bsOpts)
799815
defer ig.Close()
800816
i := ig.Next()
801817
defer i.Exchange.Close()

0 commit comments

Comments
 (0)