@@ -48,8 +48,7 @@ func addBlock(t *testing.T, ctx context.Context, inst testinstance.Instance, blk
4848}
4949
5050func TestBasicSessions (t * testing.T ) {
51- ctx , cancel := context .WithCancel (context .Background ())
52- defer cancel ()
51+ ctx := t .Context ()
5352
5453 vnet := getVirtualNetwork ()
5554 router := mockrouting .NewServer ()
@@ -133,8 +132,7 @@ func TestCustomProviderQueryManager(t *testing.T) {
133132 }
134133 defer pqm .Close ()
135134
136- ctx , cancel := context .WithCancel (context .Background ())
137- defer cancel ()
135+ ctx := t .Context ()
138136
139137 bs := bitswap .New (ctx , a .Adapter , pqm , a .Blockstore ,
140138 bitswap .WithClientOption (client .WithDefaultProviderQueryManager (false )),
@@ -173,8 +171,7 @@ func TestCustomProviderQueryManager(t *testing.T) {
173171}
174172
175173func TestSessionBetweenPeers (t * testing.T ) {
176- ctx , cancel := context .WithCancel (context .Background ())
177- defer cancel ()
174+ ctx := t .Context ()
178175
179176 vnet := tn .VirtualNetwork (delay .Fixed (time .Millisecond ))
180177 router := mockrouting .NewServer ()
@@ -212,7 +209,7 @@ func TestSessionBetweenPeers(t *testing.T) {
212209 cids = cids [1 :]
213210
214211 // Fetch blocks with the session, 10 at a time
215- for i := 0 ; i < 10 ; i ++ {
212+ for i := range 10 {
216213 ch , err := ses .GetBlocks (ctx , cids [i * 10 :(i + 1 )* 10 ])
217214 if err != nil {
218215 t .Fatal (err )
@@ -242,8 +239,7 @@ func TestSessionBetweenPeers(t *testing.T) {
242239}
243240
244241func TestSessionSplitFetch (t * testing.T ) {
245- ctx , cancel := context .WithCancel (context .Background ())
246- defer cancel ()
242+ ctx := t .Context ()
247243
248244 vnet := getVirtualNetwork ()
249245 router := mockrouting .NewServer ()
@@ -254,7 +250,7 @@ func TestSessionSplitFetch(t *testing.T) {
254250
255251 // Add 10 distinct blocks to each of 10 peers
256252 blks := random .BlocksOfSize (100 , blockSize )
257- for i := 0 ; i < 10 ; i ++ {
253+ for i := range 10 {
258254 if err := inst [i ].Blockstore .PutMany (ctx , blks [i * 10 :(i + 1 )* 10 ]); err != nil {
259255 t .Fatal (err )
260256 }
@@ -269,7 +265,7 @@ func TestSessionSplitFetch(t *testing.T) {
269265 ses := inst [10 ].Exchange .NewSession (ctx ).(* session.Session )
270266 ses .SetBaseTickDelay (time .Millisecond * 10 )
271267
272- for i := 0 ; i < 10 ; i ++ {
268+ for i := range 10 {
273269 ch , err := ses .GetBlocks (ctx , cids [i * 10 :(i + 1 )* 10 ])
274270 if err != nil {
275271 t .Fatal (err )
@@ -371,7 +367,7 @@ func TestFetchAfterDisconnect(t *testing.T) {
371367
372368 // Should get first 5 blocks
373369 var got []blocks.Block
374- for i := 0 ; i < 5 ; i ++ {
370+ for range 5 {
375371 b := <- ch
376372 got = append (got , b )
377373 }
@@ -397,7 +393,7 @@ func TestFetchAfterDisconnect(t *testing.T) {
397393 // Peer B should call FindProviders() and find Peer A
398394
399395 // Should get last 5 blocks
400- for i := 0 ; i < 5 ; i ++ {
396+ for range 5 {
401397 select {
402398 case b := <- ch :
403399 got = append (got , b )
@@ -411,8 +407,7 @@ func TestFetchAfterDisconnect(t *testing.T) {
411407}
412408
413409func TestInterestCacheOverflow (t * testing.T ) {
414- ctx , cancel := context .WithCancel (context .Background ())
415- defer cancel ()
410+ ctx := t .Context ()
416411
417412 vnet := getVirtualNetwork ()
418413 router := mockrouting .NewServer ()
@@ -461,8 +456,7 @@ func TestInterestCacheOverflow(t *testing.T) {
461456}
462457
463458func TestPutAfterSessionCacheEvict (t * testing.T ) {
464- ctx , cancel := context .WithCancel (context .Background ())
465- defer cancel ()
459+ ctx := t .Context ()
466460
467461 vnet := getVirtualNetwork ()
468462 router := mockrouting .NewServer ()
@@ -499,8 +493,7 @@ func TestPutAfterSessionCacheEvict(t *testing.T) {
499493}
500494
501495func TestMultipleSessions (t * testing.T ) {
502- ctx , cancel := context .WithCancel (context .Background ())
503- defer cancel ()
496+ ctx := t .Context ()
504497
505498 vnet := getVirtualNetwork ()
506499 router := mockrouting .NewServer ()
@@ -597,8 +590,7 @@ func TestDontHaveTimeoutConfig(t *testing.T) {
597590 }
598591 defer pqm .Close ()
599592
600- ctx , cancel := context .WithCancel (context .Background ())
601- defer cancel ()
593+ ctx := t .Context ()
602594
603595 bs := bitswap .New (ctx , a .Adapter , pqm , a .Blockstore ,
604596 bitswap .WithClientOption (client .WithDontHaveTimeoutConfig (cfg )))
0 commit comments