From a52d3b5c079d3286f556fca0afd209d54e041d80 Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Thu, 21 May 2015 11:39:59 -0400 Subject: [PATCH] put in hack to allow boltdb reader isolation test to pass in boltdb, long readers *MAY* block a writer. in particular if the write requires additional allocation, it must acquire a lock already held by the reader. in general this is not a problem for bleve (though it can affect performance in some cases), but it is a problem for the reader isolation test. this commit adds a hack to try and avoid the need for additional allocation closes #208 --- index/store/boltdb/store_test.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/index/store/boltdb/store_test.go b/index/store/boltdb/store_test.go index fc07be3a..d188de28 100644 --- a/index/store/boltdb/store_test.go +++ b/index/store/boltdb/store_test.go @@ -10,6 +10,7 @@ package boltdb import ( + "fmt" "os" "reflect" "testing" @@ -150,6 +151,31 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) { if err != nil { t.Fatal(err) } + + // ************************************************** + // this is a hack to try to pre-emptively overflow + // boltdb writes *MAY* block a long reader + // in particular, if the write requires additional + // allocation, it must acquire the same lock as + // the reader, thus cannot continue until that + // reader is closed. + // in general this is not a problem for bleve + // (though it may affect performance in some cases) + // but it is a problem for this test which attemps + // to easily verify that readers are isolated + // this hack writes enough initial data such that + // the subsequent writes do not require additional + // space + hackSize := 1000 + for i := 0; i < hackSize; i++ { + k := fmt.Sprintf("x%d", i) + err = writer.Set([]byte(k), []byte("filler")) + if err != nil { + t.Fatal(err) + } + } + // ************************************************** + err = writer.Close() if err != nil { t.Fatal(err) @@ -189,7 +215,7 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) { it.Next() count++ } - if count != 1 { + if count != hackSize+1 { t.Errorf("expected iterator to see 1, saw %d", count) } @@ -239,7 +265,7 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) { it2.Next() count++ } - if count != 2 { + if count != hackSize+2 { t.Errorf("expected iterator to see 2, saw %d", count) } @@ -265,7 +291,7 @@ func CommonTestReaderIsolation(t *testing.T, s store.KVStore) { it3.Next() count++ } - if count != 1 { + if count != hackSize+1 { t.Errorf("expected iterator to see 1, saw %d", count) }