From 0a5ca88839b8e853239c02f409a5ea813d099024 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 19 Feb 2024 15:11:58 +0100 Subject: [PATCH] fix: improve gc test by using context with cancel --- gc_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gc_test.go b/gc_test.go index a690808..1a7cb8d 100644 --- a/gc_test.go +++ b/gc_test.go @@ -14,6 +14,9 @@ func TestPeriodicGC(t *testing.T) { gnd := mustTestNode(t, Config{}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + cids := []cid.Cid{ mustAddFile(t, gnd, []byte("a")), mustAddFile(t, gnd, []byte("b")), @@ -24,7 +27,7 @@ func TestPeriodicGC(t *testing.T) { } for i, cid := range cids { - has, err := gnd.blockstore.Has(context.Background(), cid) + has, err := gnd.blockstore.Has(ctx, cid) assert.NoError(t, err, i) assert.True(t, has, i) } @@ -35,11 +38,11 @@ func TestPeriodicGC(t *testing.T) { // not if the timer is being correctly set-up. // // Tracked in https://github.com/ipfs/rainbow/issues/89 - err := gnd.periodicGC(context.Background(), 1) + err := gnd.periodicGC(ctx, 1) require.NoError(t, err) for i, cid := range cids { - has, err := gnd.blockstore.Has(context.Background(), cid) + has, err := gnd.blockstore.Has(ctx, cid) assert.NoError(t, err, i) assert.False(t, has, i) }