-
Notifications
You must be signed in to change notification settings - Fork 12
/
gc_test.go
51 lines (42 loc) · 1.2 KB
/
gc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"context"
"testing"
"github.com/ipfs/go-cid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPeriodicGC(t *testing.T) {
t.Parallel()
gnd := mustTestNode(t, Config{
Bitswap: true,
})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cids := []cid.Cid{
mustAddFile(t, gnd, []byte("a")),
mustAddFile(t, gnd, []byte("b")),
mustAddFile(t, gnd, []byte("c")),
mustAddFile(t, gnd, []byte("d")),
mustAddFile(t, gnd, []byte("e")),
mustAddFile(t, gnd, []byte("f")),
}
for i, cid := range cids {
has, err := gnd.blockstore.Has(ctx, cid)
assert.NoError(t, err, i)
assert.True(t, has, i)
}
// NOTE: ideally, we'd be able to spawn an isolated Rainbow instance with the
// periodic GC settings configured (interval, threshold). The way it is now,
// we can only test if the periodicGC function and the GC function work, but
// not if the timer is being correctly set-up.
//
// Tracked in https://github.com/ipfs/rainbow/issues/89
err := gnd.periodicGC(ctx, 1)
require.NoError(t, err)
for i, cid := range cids {
has, err := gnd.blockstore.Has(ctx, cid)
assert.NoError(t, err, i)
assert.False(t, has, i)
}
}