mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-02 13:43:11 +00:00
make all tests pass
This commit is contained in:
parent
bee79ffe72
commit
84681cd8ef
@ -19,7 +19,7 @@ import pkg/datastore/threads/asyncsemaphore
|
||||
randomize()
|
||||
|
||||
suite "AsyncSemaphore":
|
||||
test "should acquire":
|
||||
test "Should acquire":
|
||||
let sema = AsyncSemaphore.new(3)
|
||||
|
||||
await sema.acquire()
|
||||
@ -28,7 +28,7 @@ suite "AsyncSemaphore":
|
||||
|
||||
check sema.count == 0
|
||||
|
||||
test "should release":
|
||||
test "Should release":
|
||||
let sema = AsyncSemaphore.new(3)
|
||||
|
||||
await sema.acquire()
|
||||
@ -41,7 +41,7 @@ suite "AsyncSemaphore":
|
||||
sema.release()
|
||||
check sema.count == 3
|
||||
|
||||
test "should queue acquire":
|
||||
test "Should queue acquire":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
|
||||
await sema.acquire()
|
||||
@ -55,19 +55,19 @@ suite "AsyncSemaphore":
|
||||
await sleepAsync(10.millis)
|
||||
check fut.finished()
|
||||
|
||||
test "should keep count == size":
|
||||
test "Should keep count == size":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
sema.release()
|
||||
sema.release()
|
||||
sema.release()
|
||||
check sema.count == 1
|
||||
|
||||
test "should tryAcquire":
|
||||
test "Should tryAcquire":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
await sema.acquire()
|
||||
check sema.tryAcquire() == false
|
||||
|
||||
test "should tryAcquire and acquire":
|
||||
test "Should tryAcquire and acquire":
|
||||
let sema = AsyncSemaphore.new(4)
|
||||
check sema.tryAcquire() == true
|
||||
check sema.tryAcquire() == true
|
||||
@ -88,7 +88,7 @@ suite "AsyncSemaphore":
|
||||
check fut.finished == true
|
||||
check sema.count == 4
|
||||
|
||||
test "should restrict resource access":
|
||||
test "Should restrict resource access":
|
||||
let sema = AsyncSemaphore.new(3)
|
||||
var resource = 0
|
||||
|
||||
@ -110,7 +110,7 @@ suite "AsyncSemaphore":
|
||||
|
||||
await allFutures(tasks)
|
||||
|
||||
test "should cancel sequential semaphore slot":
|
||||
test "Should cancel sequential semaphore slot":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
|
||||
await sema.acquire()
|
||||
@ -131,7 +131,7 @@ suite "AsyncSemaphore":
|
||||
|
||||
check await sema.acquire().withTimeout(10.millis)
|
||||
|
||||
test "should handle out of order cancellations":
|
||||
test "Should handle out of order cancellations":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
|
||||
await sema.acquire() # 1st acquire
|
||||
@ -156,20 +156,20 @@ suite "AsyncSemaphore":
|
||||
sema.release() # 4th release
|
||||
check await sema.acquire().withTimeout(10.millis)
|
||||
|
||||
test "should properly handle timeouts and cancellations":
|
||||
test "Should properly handle timeouts and cancellations":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
|
||||
await sema.acquire()
|
||||
check not(await sema.acquire().withTimeout(1.millis)) # should not acquire but cancel
|
||||
check not(await sema.acquire().withTimeout(1.millis)) # Should not acquire but cancel
|
||||
sema.release()
|
||||
|
||||
check await sema.acquire().withTimeout(10.millis)
|
||||
|
||||
test "should handle forceAcquire properly":
|
||||
test "Should handle forceAcquire properly":
|
||||
let sema = AsyncSemaphore.new(1)
|
||||
|
||||
await sema.acquire()
|
||||
check not(await sema.acquire().withTimeout(1.millis)) # should not acquire but cancel
|
||||
check not(await sema.acquire().withTimeout(1.millis)) # Should not acquire but cancel
|
||||
|
||||
let
|
||||
fut1 = sema.acquire()
|
||||
|
||||
@ -34,7 +34,7 @@ suite "Test Basic ThreadDatastore with SQLite":
|
||||
setupAll:
|
||||
sqlStore = SQLiteDatastore.new(Memory).tryGet()
|
||||
taskPool = Taskpool.new(countProcessors() * 2)
|
||||
ds = ThreadDatastore.new(sqlStore, taskPool).tryGet()
|
||||
ds = ThreadDatastore.new(sqlStore, tp = taskPool).tryGet()
|
||||
|
||||
teardownAll:
|
||||
(await ds.close()).tryGet()
|
||||
@ -42,7 +42,6 @@ suite "Test Basic ThreadDatastore with SQLite":
|
||||
|
||||
basicStoreTests(ds, key, bytes, otherBytes)
|
||||
|
||||
|
||||
suite "Test Query ThreadDatastore with SQLite":
|
||||
|
||||
var
|
||||
@ -56,7 +55,7 @@ suite "Test Query ThreadDatastore with SQLite":
|
||||
setup:
|
||||
sqlStore = SQLiteDatastore.new(Memory).tryGet()
|
||||
taskPool = Taskpool.new(countProcessors() * 2)
|
||||
ds = ThreadDatastore.new(sqlStore, taskPool).tryGet()
|
||||
ds = ThreadDatastore.new(sqlStore, tp = taskPool).tryGet()
|
||||
|
||||
teardown:
|
||||
(await ds.close()).tryGet()
|
||||
@ -64,23 +63,68 @@ suite "Test Query ThreadDatastore with SQLite":
|
||||
|
||||
queryTests(ds, true)
|
||||
|
||||
# TODO: needs a per key lock to work
|
||||
# suite "Test Basic ThreadDatastore with fsds":
|
||||
suite "Test Basic ThreadDatastore with fsds":
|
||||
let
|
||||
path = currentSourcePath() # get this file's name
|
||||
basePath = "tests_data"
|
||||
basePathAbs = path.parentDir / basePath
|
||||
key = Key.init("/a/b").tryGet()
|
||||
bytes = "some bytes".toBytes
|
||||
otherBytes = "some other bytes".toBytes
|
||||
|
||||
# let
|
||||
# path = currentSourcePath() # get this file's name
|
||||
# basePath = "tests_data"
|
||||
# basePathAbs = path.parentDir / basePath
|
||||
# key = Key.init("/a/b").tryGet()
|
||||
# bytes = "some bytes".toBytes
|
||||
# otherBytes = "some other bytes".toBytes
|
||||
var
|
||||
fsStore: FSDatastore
|
||||
ds: ThreadDatastore
|
||||
taskPool: Taskpool
|
||||
|
||||
# var
|
||||
# fsStore: FSDatastore
|
||||
# ds: ThreadDatastore
|
||||
# taskPool: Taskpool
|
||||
setupAll:
|
||||
removeDir(basePathAbs)
|
||||
require(not dirExists(basePathAbs))
|
||||
createDir(basePathAbs)
|
||||
|
||||
suite "Test ThreadDatastore":
|
||||
fsStore = FSDatastore.new(root = basePathAbs, depth = 3).tryGet()
|
||||
taskPool = Taskpool.new(countProcessors() * 2)
|
||||
ds = ThreadDatastore.new(fsStore, withLocks = true, tp = taskPool).tryGet()
|
||||
|
||||
teardownAll:
|
||||
(await ds.close()).tryGet()
|
||||
taskPool.shutdown()
|
||||
|
||||
removeDir(basePathAbs)
|
||||
require(not dirExists(basePathAbs))
|
||||
|
||||
basicStoreTests(fsStore, key, bytes, otherBytes)
|
||||
|
||||
suite "Test Query ThreadDatastore with fsds":
|
||||
let
|
||||
path = currentSourcePath() # get this file's name
|
||||
basePath = "tests_data"
|
||||
basePathAbs = path.parentDir / basePath
|
||||
|
||||
var
|
||||
fsStore: FSDatastore
|
||||
ds: ThreadDatastore
|
||||
taskPool: Taskpool
|
||||
|
||||
setup:
|
||||
removeDir(basePathAbs)
|
||||
require(not dirExists(basePathAbs))
|
||||
createDir(basePathAbs)
|
||||
|
||||
fsStore = FSDatastore.new(root = basePathAbs, depth = 5).tryGet()
|
||||
taskPool = Taskpool.new(countProcessors() * 2)
|
||||
ds = ThreadDatastore.new(fsStore, withLocks = true, tp = taskPool).tryGet()
|
||||
|
||||
teardown:
|
||||
(await ds.close()).tryGet()
|
||||
taskPool.shutdown()
|
||||
|
||||
removeDir(basePathAbs)
|
||||
require(not dirExists(basePathAbs))
|
||||
|
||||
queryTests(ds, false)
|
||||
|
||||
suite "Test ThreadDatastore cancelations":
|
||||
var
|
||||
sqlStore: Datastore
|
||||
ds: ThreadDatastore
|
||||
@ -95,9 +139,9 @@ suite "Test ThreadDatastore":
|
||||
setupAll:
|
||||
sqlStore = SQLiteDatastore.new(Memory).tryGet()
|
||||
taskPool = Taskpool.new(countProcessors() * 2)
|
||||
ds = ThreadDatastore.new(sqlStore, taskPool).tryGet()
|
||||
ds = ThreadDatastore.new(sqlStore, tp = taskPool).tryGet()
|
||||
|
||||
test "should monitor signal for cancellations and cancel":
|
||||
test "Should monitor signal and cancel":
|
||||
var
|
||||
signal = ThreadSignalPtr.new().tryGet()
|
||||
res = ThreadResult[void]()
|
||||
@ -130,7 +174,7 @@ suite "Test ThreadDatastore":
|
||||
check: fut.cancelled
|
||||
check: ctx.signal.close().isOk
|
||||
|
||||
test "should monitor signal for cancellations and not cancel":
|
||||
test "Should monitor and not cancel":
|
||||
var
|
||||
signal = ThreadSignalPtr.new().tryGet()
|
||||
res = ThreadResult[void]()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user