sorted/kvtest: close iterator ASAP to make sqlite happy

Change-Id: I7dcca4447bea262fedc6a5fbe572034bfd8cc61d
This commit is contained in:
mpl 2015-03-12 16:15:56 +01:00
parent dcab33a2ae
commit f6bf779cd6
2 changed files with 6 additions and 1 deletions

View File

@ -96,12 +96,14 @@ func testInsertLarge(t *testing.T, kv sorted.KeyValue) {
if err := kv.Set(string(largeKey), "whatever"); err != nil {
t.Fatalf("Insertion of large key failed: %v", err)
}
// and verify we can get it back, i.e. that the key hasn't been truncated.
it := kv.Find(string(largeKey), "")
defer it.Close()
if !it.Next() || it.Key() != string(largeKey) || it.Value() != "whatever" {
it.Close()
t.Fatalf("Find(largeKey) = %q, %q; want %q, %q", it.Key(), it.Value(), largeKey, "whatever")
}
it.Close()
// insert with large value
if err := kv.Set("whatever", string(largeValue)); err != nil {

View File

@ -177,6 +177,9 @@ func (kv *KeyValue) Close() error { return kv.DB.Close() }
func (kv *KeyValue) Find(start, end string) sorted.Iterator {
if kv.Serial {
kv.mu.Lock()
// TODO(mpl): looks like sqlite considers the db locked until we've closed
// the iterator, so we can't do anything else until then. We should probably
// move that Unlock to the closing of the iterator. Investigating.
defer kv.mu.Unlock()
}
var rows *sql.Rows