Skip to content

Commit

Permalink
fix: improve gc test by using context with cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Feb 19, 2024
1 parent d7b8111 commit 0a5ca88
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 0a5ca88

Please sign in to comment.