Skip to content

Commit

Permalink
Concurrent iterator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benbierens committed May 28, 2024
1 parent 3cb2189 commit c70c51f
Showing 1 changed file with 118 additions and 4 deletions.
122 changes: 118 additions & 4 deletions tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ proc execTool(args: varargs[string]): tuple[output: string, exitCode: int] =
checkpoint(result.output)

suite "leveldb":

setup:
let env = leveldb_create_default_env()
let dbName = $(leveldb_env_get_test_directory(env))
Expand Down Expand Up @@ -206,7 +205,6 @@ suite "leveldb":
check(toSeq(nc.iter()) == @[("a", "1")])

suite "leveldb queryIter":

setup:
let env = leveldb_create_default_env()
let dbName = $(leveldb_env_get_test_directory(env))
Expand Down Expand Up @@ -332,8 +330,125 @@ suite "leveldb queryIter":
iter.next() == empty
iter.finished

suite "package":
test "concurrent iterators - 1":
let
iter1 = db.queryIter()
iter2 = db.queryIter()

check:
# 1, then 2
not iter1.finished
iter1.next() == (k1, v1)

not iter2.finished
iter2.next() == (k1, v1)

# 1, 1, then 2, 2
not iter1.finished
iter1.next() == (k2, v2)
not iter1.finished
iter1.next() == (k3, v3)

not iter2.finished
iter2.next() == (k2, v2)
not iter2.finished
iter2.next() == (k3, v3)

# finish 1, then finish 2
not iter1.finished
iter1.next() == empty

not iter2.finished
iter2.next() == empty

iter1.finished
iter2.finished

test "concurrent iterators - 2":
let
iter1 = db.queryIter()
iter2 = db.queryIter()

check:
# 1, then 2
not iter1.finished
iter1.next() == (k1, v1)

not iter2.finished
iter2.next() == (k1, v1)

# finish 1
not iter1.finished
iter1.next() == (k2, v2)
not iter1.finished
iter1.next() == (k3, v3)
not iter1.finished
iter1.next() == empty
iter1.finished

# finish 2
not iter2.finished
iter2.next() == (k2, v2)
not iter2.finished
iter2.next() == (k3, v3)
not iter2.finished
iter2.next() == empty
iter2.finished

test "concurrent iterators - dispose":
let
iter1 = db.queryIter()
iter2 = db.queryIter()

check:
# 1, then 2
not iter1.finished
iter1.next() == (k1, v1)

not iter2.finished
iter2.next() == (k1, v1)

# dispose 1
iter1.dispose()

check:
iter1.finished
iter1.next() == empty
iter1.finished

# finish 2
not iter2.finished
iter2.next() == (k2, v2)
not iter2.finished
iter2.next() == (k3, v3)
not iter2.finished
iter2.next() == empty
iter2.finished

test "modify while iterating":
let
iter = db.queryIter()

check:
not iter.finished
iter.next() == (k1, v1)
not iter.finished
iter.next() == (k2, v2)

# insert
let
k4 = "k4"
v4 = "v4"
db.put(k4, v4)

check:
not iter.finished
iter.next() == (k3, v3)
not iter.finished
iter.next() == empty
iter.finished

suite "package":
setup:
removeDir(tmpDir)

Expand All @@ -353,7 +468,6 @@ suite "package":
check output.contains("leveldb works.")

suite "tool":

setup:
removeDir(tmpDir)

Expand Down

0 comments on commit c70c51f

Please sign in to comment.