From 0eb5881662a5227d49f933c9a8cb49f23d9c709d Mon Sep 17 00:00:00 2001 From: siddontang Date: Tue, 6 May 2014 10:32:34 +0800 Subject: [PATCH] update leveled iterator test --- leveldb/leveldb_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/leveldb/leveldb_test.go b/leveldb/leveldb_test.go index 06b94f8..6b9934b 100644 --- a/leveldb/leveldb_test.go +++ b/leveldb/leveldb_test.go @@ -279,6 +279,8 @@ func TestIterator_2(t *testing.T) { t.Fatal(string(it.Key())) } + it.Close() + it = db.ReverseIterator([]byte("key_8"), []byte("key_0"), 0) if !it.Valid() { t.Fatal("must valid") @@ -288,20 +290,27 @@ func TestIterator_2(t *testing.T) { t.Fatal(string(it.Key())) } - for it := db.Iterator(nil, nil, 0); it.Valid(); it.Next() { + it.Close() + + for it = db.Iterator(nil, nil, 0); it.Valid(); it.Next() { db.Delete(it.Key()) } + it.Close() + it = db.Iterator([]byte("key_0"), []byte("key_8"), 0) if it.Valid() { t.Fatal("must not valid") } + it.Close() + it = db.ReverseIterator([]byte("key_8"), []byte("key_0"), 0) if it.Valid() { t.Fatal("must not valid") } + it.Close() } func TestSnapshot(t *testing.T) { @@ -324,25 +333,30 @@ func TestSnapshot(t *testing.T) { } found := false - for it := s.Iterator(nil, nil, 0); it.Valid(); it.Next() { + var it *Iterator + for it = s.Iterator(nil, nil, 0); it.Valid(); it.Next() { if string(it.Key()) == string(key) { found = true break } } + it.Close() + if !found { t.Fatal("must found") } found = false - for it := s.ReverseIterator(nil, nil, 0); it.Valid(); it.Next() { + for it = s.ReverseIterator(nil, nil, 0); it.Valid(); it.Next() { if string(it.Key()) == string(key) { found = true break } } + it.Close() + if !found { t.Fatal("must found") }