test: add test case for PutMany on bloom filter skipping add to bloom
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Aug 31, 2016 at 17:27 UTC
d080ff19dd8e661c16bc131f93f1f3f062192b79
1 file changed
+33
blocks/blockstore/bloom_cache_test.go
+33
@@ -28,6 +28,39 @@ func testBloomCached(bs GCBlockstore, ctx context.Context) (*bloomcache, error)
28
}
29
}
30
31
+func TestPutManyAddsToBloom(t *testing.T) {
32
+ bs := NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
33
+
34
+ ctx, _ := context.WithTimeout(context.Background(), 1*time.Second)
35
+ cachedbs, err := testBloomCached(bs, ctx)
36
+
37
+ select {
38
+ case <-cachedbs.rebuildChan:
39
+ case <-ctx.Done():
40
+ t.Fatalf("Timeout wating for rebuild: %d", cachedbs.bloom.ElementsAdded())
41
+ }
42
+
43
+ block1 := blocks.NewBlock([]byte("foo"))
44
+ block2 := blocks.NewBlock([]byte("bar"))
45
+
46
+ cachedbs.PutMany([]blocks.Block{block1})
47
+ has, err := cachedbs.Has(block1.Key())
48
+ if err != nil {
49
+ t.Fatal(err)
50
+ }
51
+ if has == false {
52
+ t.Fatal("added block is reported missing")
53
+ }
54
+
55
+ has, err = cachedbs.Has(block2.Key())
56
+ if err != nil {
57
+ t.Fatal(err)
58
+ }
59
+ if has == true {
60
+ t.Fatal("not added block is reported to be in blockstore")
61
+ }
62
+}
63
+
64
func TestReturnsErrorWhenSizeNegative(t *testing.T) {
65
bs := NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
66
_, err := bloomCached(bs, context.TODO(), -1, 1)