2023-08-24 19:51:04 -07:00
|
|
|
import std/options
|
|
|
|
|
import std/sequtils
|
|
|
|
|
import std/os
|
2023-08-28 21:45:55 -07:00
|
|
|
import std/algorithm
|
2023-08-24 19:51:04 -07:00
|
|
|
|
|
|
|
|
import pkg/asynctest/unittest2
|
|
|
|
|
import pkg/chronos
|
|
|
|
|
import pkg/stew/results
|
|
|
|
|
import pkg/stew/byteutils
|
|
|
|
|
|
2023-08-28 21:45:55 -07:00
|
|
|
import pkg/datastore/memoryds
|
2023-08-29 12:50:36 -07:00
|
|
|
import pkg/datastore/threadproxyds
|
2023-08-24 19:51:04 -07:00
|
|
|
|
|
|
|
|
import ./dscommontests
|
|
|
|
|
import ./querycommontests
|
|
|
|
|
|
2023-08-24 22:20:49 -07:00
|
|
|
import pretty
|
|
|
|
|
|
2023-08-29 14:40:44 -07:00
|
|
|
|
2023-08-29 12:50:36 -07:00
|
|
|
suite "Test Basic ThreadProxyDatastore":
|
2023-08-28 22:26:00 -07:00
|
|
|
var
|
2023-08-29 12:50:36 -07:00
|
|
|
sds: ThreadProxyDatastore
|
2023-08-28 22:26:00 -07:00
|
|
|
mem: MemoryDatastore
|
|
|
|
|
key1: Key
|
|
|
|
|
data: seq[byte]
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-28 22:26:00 -07:00
|
|
|
setupAll:
|
|
|
|
|
mem = MemoryDatastore.new()
|
2023-08-29 14:43:05 -07:00
|
|
|
sds = newThreadProxyDatastore(mem).expect("should work")
|
2023-08-28 22:26:00 -07:00
|
|
|
key1 = Key.init("/a").tryGet
|
|
|
|
|
data = "value for 1".toBytes()
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-28 22:26:00 -07:00
|
|
|
test "check put":
|
2023-08-24 21:55:53 -07:00
|
|
|
echo "\n\n=== put ==="
|
2023-08-28 22:26:00 -07:00
|
|
|
let res1 = await sds.put(key1, data)
|
2023-08-25 15:00:18 -07:00
|
|
|
print "res1: ", res1
|
2023-08-24 21:55:53 -07:00
|
|
|
|
2023-08-28 22:26:00 -07:00
|
|
|
test "check get":
|
2023-08-24 22:14:21 -07:00
|
|
|
echo "\n\n=== get ==="
|
|
|
|
|
let res2 = await sds.get(key1)
|
2023-08-28 22:26:00 -07:00
|
|
|
check res2.get() == data
|
2023-08-24 22:14:21 -07:00
|
|
|
var val = ""
|
|
|
|
|
for c in res2.get():
|
|
|
|
|
val &= char(c)
|
2023-08-24 22:20:49 -07:00
|
|
|
print "get res2: ", $val
|
2023-08-24 22:14:21 -07:00
|
|
|
|
2023-08-28 22:26:00 -07:00
|
|
|
# echo "\n\n=== put cancel ==="
|
|
|
|
|
# # let res1 = await sds.put(key1, "value for 1".toBytes())
|
|
|
|
|
# let res3 = sds.put(key1, "value for 1".toBytes())
|
|
|
|
|
# res3.cancel()
|
|
|
|
|
# # print "res3: ", res3
|
2023-08-25 15:00:18 -07:00
|
|
|
|
2023-08-29 12:50:36 -07:00
|
|
|
suite "Test Basic ThreadProxyDatastore":
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-28 21:56:29 -07:00
|
|
|
var
|
|
|
|
|
memStore: MemoryDatastore
|
2023-08-29 12:50:36 -07:00
|
|
|
ds: ThreadProxyDatastore
|
2023-08-28 21:56:29 -07:00
|
|
|
key = Key.init("/a/b").tryGet()
|
|
|
|
|
bytes = "some bytes".toBytes
|
|
|
|
|
otherBytes = "some other bytes".toBytes
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-28 21:56:29 -07:00
|
|
|
setupAll:
|
|
|
|
|
memStore = MemoryDatastore.new()
|
2023-08-29 14:43:05 -07:00
|
|
|
ds = newThreadProxyDatastore(memStore).expect("should work")
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-28 21:56:29 -07:00
|
|
|
teardownAll:
|
|
|
|
|
(await memStore.close()).get()
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-28 22:18:08 -07:00
|
|
|
basicStoreTests(ds, key, bytes, otherBytes)
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-29 16:40:11 -07:00
|
|
|
suite "Test Query":
|
|
|
|
|
var
|
|
|
|
|
mem: MemoryDatastore
|
|
|
|
|
sds: ThreadProxyDatastore
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-29 16:40:11 -07:00
|
|
|
setup:
|
|
|
|
|
mem = MemoryDatastore.new()
|
|
|
|
|
sds = newThreadProxyDatastore(mem).expect("should work")
|
2023-08-24 19:51:04 -07:00
|
|
|
|
2023-08-29 16:40:11 -07:00
|
|
|
queryTests(sds, false)
|
2023-08-29 17:00:11 -07:00
|
|
|
|