mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-04 22:53:08 +00:00
cleanup test
This commit is contained in:
parent
4fa8dc3c67
commit
6557e59dc4
@ -17,32 +17,33 @@ template checkNotNil(p: typed) =
|
||||
if p.isNil:
|
||||
raiseNilAccess()
|
||||
|
||||
import std/terminal
|
||||
import std/locks
|
||||
var elock: Lock
|
||||
elock.initLock()
|
||||
|
||||
proc echoed*(vals: varargs[string, `$`]) =
|
||||
proc printThread(): ForegroundColor =
|
||||
let tclr = [fgRed, fgGreen, fgBlue, fgMagenta, fgCyan]
|
||||
let tid = getThreadId()
|
||||
let color = tclr[(tid mod (tclr.len() - 1))]
|
||||
stdout.styledWrite(styleBright, fgWhite, "(thr: ", color, $tid, fgWhite, ") ")
|
||||
color
|
||||
try:
|
||||
let color = printThread()
|
||||
var i = 0
|
||||
if vals.len() mod 2 != 0:
|
||||
stdout.styledWrite(color, vals[i])
|
||||
i.inc()
|
||||
while i + 1 < vals.len():
|
||||
stdout.styledWrite(color, vals[i], fgDefault, vals[i+1])
|
||||
i.inc(2)
|
||||
stdout.styledWrite("\n")
|
||||
except:
|
||||
discard
|
||||
finally:
|
||||
when not defined(datastoreEchoString):
|
||||
proc echoed*(vals: varargs[string, `$`]) =
|
||||
discard
|
||||
else:
|
||||
import std/terminal
|
||||
proc echoed*(vals: varargs[string, `$`]) =
|
||||
proc printThread(): ForegroundColor =
|
||||
let tclr = [fgRed, fgGreen, fgBlue, fgMagenta, fgCyan]
|
||||
let tid = getThreadId()
|
||||
let color = tclr[(tid mod (tclr.len() - 1))]
|
||||
stdout.styledWrite(styleBright, fgWhite, "(thr: ", color, $tid, fgWhite, ") ")
|
||||
color
|
||||
try:
|
||||
let color = printThread()
|
||||
var i = 0
|
||||
if vals.len() mod 2 != 0:
|
||||
stdout.styledWrite(color, vals[i])
|
||||
i.inc()
|
||||
while i + 1 < vals.len():
|
||||
stdout.styledWrite(color, vals[i], fgDefault, vals[i+1])
|
||||
i.inc(2)
|
||||
stdout.styledWrite("\n")
|
||||
except:
|
||||
discard
|
||||
finally:
|
||||
discard
|
||||
|
||||
type
|
||||
SharedPtr*[T] = object
|
||||
|
||||
@ -110,7 +110,10 @@ proc getTask*(
|
||||
tds: ThreadDatastorePtr,
|
||||
kb: KeyBuffer,
|
||||
) =
|
||||
echo "\n"
|
||||
echoed "getTask: ", $getThreadId()
|
||||
let key = kb.toKey()
|
||||
echoed "getTask: key: ", $key
|
||||
try:
|
||||
let res = waitFor tds[].ds.get(key)
|
||||
if res.isErr:
|
||||
@ -133,7 +136,7 @@ proc putTask*(
|
||||
db: DataBuffer,
|
||||
) =
|
||||
|
||||
# os.sleep(400)
|
||||
# os.sleep(1_000)
|
||||
# var ret = ret
|
||||
echo "\n"
|
||||
echoed "putTask: ", $getThreadId()
|
||||
|
||||
@ -18,32 +18,32 @@ type
|
||||
val: ref T
|
||||
|
||||
proc `=destroy`(obj: var TestObj) =
|
||||
echo "test obj destroy"
|
||||
# echo "test obj destroy"
|
||||
obj.val[] = 0
|
||||
|
||||
proc `=destroy`[T: int](obj: var TestObjGen[T]) =
|
||||
echo "test obj destroy"
|
||||
# echo "test obj destroy"
|
||||
obj.val[] = 0
|
||||
|
||||
proc destroyTest(intref: ref int) =
|
||||
let a: SharedPtr[TestObj] = newSharedPtr(unsafeIsolate TestObj(val: intref))
|
||||
echo "a[]: ", a[]
|
||||
# echo "a[]: ", a[]
|
||||
check a[].val[] == 10
|
||||
|
||||
proc runDestroyTest() =
|
||||
echo "\nintref setup:\n"
|
||||
# echo "\nintref setup:\n"
|
||||
let intref: ref int = new(ref int)
|
||||
intref[] = 10
|
||||
destroyTest(intref)
|
||||
check intref[] == 0
|
||||
|
||||
proc runDestroyOnReleaseTest() =
|
||||
echo "\nintref setup:\n"
|
||||
# echo "\nintref setup:\n"
|
||||
let intref: ref int = new(ref int)
|
||||
intref[] = 20
|
||||
var a: SharedPtr[TestObj] = newSharedPtr(unsafeIsolate TestObj(val: intref))
|
||||
try:
|
||||
echo "a[]: ", a[]
|
||||
# echo "a[]: ", a[]
|
||||
check a[].val[] == 20
|
||||
finally:
|
||||
a.release()
|
||||
@ -81,12 +81,12 @@ suite "Share buffer test":
|
||||
runDestroyOnReleaseTest()
|
||||
|
||||
test "test destroy release no proc":
|
||||
echo "\nintref setup:\n"
|
||||
# echo "\nintref setup:\n"
|
||||
let intref: ref int = new(ref int)
|
||||
intref[] = 30
|
||||
var a: SharedPtr[TestObj] = newSharedPtr(unsafeIsolate TestObj(val: intref))
|
||||
try:
|
||||
echo "a[]: ", a[]
|
||||
# echo "a[]: ", a[]
|
||||
check a[].val[] == 30
|
||||
finally:
|
||||
a.release()
|
||||
@ -98,24 +98,24 @@ suite "Share buffer test":
|
||||
a.decr()
|
||||
|
||||
test "test destroy release generic no proc":
|
||||
echo "\nintref setup:\n"
|
||||
# echo "\nintref setup:\n"
|
||||
let intref: ref int = new(ref int)
|
||||
intref[] = 30
|
||||
var b: SharedPtr[TestObjGen[int]] = newSharedPtr(unsafeIsolate TestObjGen[int](val: intref))
|
||||
try:
|
||||
echo "a[]: ", b[]
|
||||
# echo "a[]: ", b[]
|
||||
check b[].val[] == 30
|
||||
finally:
|
||||
b.release()
|
||||
check intref[] == 0
|
||||
|
||||
test "test manual release / decr":
|
||||
echo "\nintref setup:\n"
|
||||
# echo "\nintref setup:\n"
|
||||
let intref: ref int = new(ref int)
|
||||
intref[] = 40
|
||||
var b = newSharedPtr(unsafeIsolate TestObjGen[int](val: intref), manualCount = 2)
|
||||
try:
|
||||
echo "a[]: ", b[]
|
||||
# echo "a[]: ", b[]
|
||||
check b[].val[] == 40
|
||||
finally:
|
||||
b.decr()
|
||||
|
||||
@ -41,10 +41,12 @@ suite "Test Basic ThreadProxyDatastore":
|
||||
check res1.isOk
|
||||
|
||||
test "check get":
|
||||
# echo "\n\n=== get ==="
|
||||
echo "\n\n=== get ==="
|
||||
print "get send key: ", key1
|
||||
let res2 = await sds.get(key1)
|
||||
check res2.get() == data
|
||||
print "get key post: ", key1
|
||||
print "get res2: ", res2
|
||||
check res2.get() == data
|
||||
var val = ""
|
||||
for c in res2.get():
|
||||
val &= char(c)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user