Skip to content

Commit c7f7e2e

Browse files
authored
test: cleanup goroutines at end of test (#1084)
Close test instances at the end of the test so that the do not leak beyond the end of the test. This will allow goroutine leak detection to work and will allow these tests to be wrapped in a synctest time bubble in the future.
1 parent de0b141 commit c7f7e2e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bitswap/bitswap_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
332332
t.Fatal(err)
333333
}
334334
}
335+
336+
for _, inst := range instances {
337+
err := inst.Exchange.Close()
338+
if err != nil {
339+
t.Fatal(err)
340+
}
341+
}
335342
}
336343

337344
// TODO simplify this test. get to the _essence_!
@@ -375,6 +382,13 @@ func TestSendToWantingPeer(t *testing.T) {
375382
if !blkrecvd.Cid().Equals(alpha.Cid()) {
376383
t.Fatal("Wrong block!")
377384
}
385+
386+
for _, inst := range peers {
387+
err := inst.Exchange.Close()
388+
if err != nil {
389+
t.Fatal(err)
390+
}
391+
}
378392
}
379393

380394
func TestEmptyKey(t *testing.T) {
@@ -391,6 +405,10 @@ func TestEmptyKey(t *testing.T) {
391405
if !ipld.IsNotFound(err) {
392406
t.Error("empty string key should return ErrNotFound")
393407
}
408+
409+
if err = bs.Close(); err != nil {
410+
t.Fatal(err)
411+
}
394412
}
395413

396414
func assertStat(t *testing.T, st *bitswap.Stat, sblks, rblks, sdata, rdata uint64) {
@@ -557,6 +575,8 @@ func TestWantlistCleanup(t *testing.T) {
557575
instances := ig.Instances(2)
558576
instance := instances[0]
559577
bswap := instance.Exchange
578+
defer bswap.Close()
579+
defer instances[1].Exchange.Close()
560580
blocks := random.BlocksOfSize(20, blockSize)
561581

562582
var keys []cid.Cid

0 commit comments

Comments
 (0)