mirror of https://github.com/perkeep/perkeep.git
sorted/kvtest: close iterator ASAP to make sqlite happy
Change-Id: I7dcca4447bea262fedc6a5fbe572034bfd8cc61d
This commit is contained in:
parent
dcab33a2ae
commit
f6bf779cd6
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue