diff --git a/roaring/roaring_pooling_test.go b/roaring/roaring_pooling_test.go new file mode 100644 index 00000000..ec6945ae --- /dev/null +++ b/roaring/roaring_pooling_test.go @@ -0,0 +1,43 @@ +package roaring + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +// TestBitmap_Reset verifies that the Reset method always restores a Bitmap +// to a state indistinguishable from a new one. +func TestBitmap_Reset(t *testing.T) { + bm := NewBitmapWithDefaultPooling(10) + + i := uint64(0) + for { + if i >= 10000 { + break + } + + bm.Add(10000 * i) + i++ + } + untouched := NewBitmapWithDefaultPooling(10) + bm.Reset() + + if !cmp.Equal(untouched, bm, cmp.Comparer(func(x, y Bitmap) bool { + if x.Containers.Size() != y.Containers.Size() { + return false + } + if x.Containers.Count() != y.Containers.Count() { + return false + } + if x.opN != y.opN { + return false + } + if x.OpWriter != y.OpWriter { + return false + } + return true + })) { + t.Fatalf("Reset bitmap: %+v is not identical to new bitmap: %+v", bm, untouched) + } +} diff --git a/roaring/roaring_test.go b/roaring/roaring_test.go index fafc0f9d..694a4746 100644 --- a/roaring/roaring_test.go +++ b/roaring/roaring_test.go @@ -1406,28 +1406,6 @@ func TestBitmap_Intersect(t *testing.T) { } } -// TestBitmap_Reset verifies that the Reset method always restores a Bitmap -// to a state indistinguishable from a new one. -func TestBitmap_Reset(t *testing.T) { - bm := roaring.NewBitmapWithDefaultPooling(10) - - i := uint64(0) - for { - if i >= 10000 { - break - } - - bm.Add(10000 * i) - i++ - } - - untouched := roaring.NewBitmapWithDefaultPooling(10) - bm.Reset() - if !reflect.DeepEqual(untouched, bm) { - t.Fatalf("Reset bitmap: %+v is not identical to new bitmap: %+v", bm, untouched) - } -} - func BenchmarkGetBenchData(b *testing.B) { for i := 0; i < b.N; i++ { sampleData = benchmarkSampleData{} diff --git a/translate.go b/translate.go index 9ef7e9a2..63adb00f 100644 --- a/translate.go +++ b/translate.go @@ -252,6 +252,8 @@ func (s *TranslateFile) size() int64 { // isReadOnly returns true if this store is being replicated from a primary store. func (s *TranslateFile) isReadOnly() bool { + s.mu.RLock() + defer s.mu.RUnlock() return s.PrimaryTranslateStore != nil }