mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-08 00:23:10 +00:00
test task cancel
This commit is contained in:
parent
43520c3608
commit
47fd3ba61f
@ -178,11 +178,13 @@ suite "Test ThreadDatastore cancelations":
|
||||
signal = ThreadSignalPtr.new().tryGet()
|
||||
ms {.global.}: MutexSignal
|
||||
flag {.global.}: Atomic[bool]
|
||||
futFreed {.global.}: Atomic[bool]
|
||||
ready {.global.}: Atomic[bool]
|
||||
|
||||
ms.init()
|
||||
|
||||
type
|
||||
FutTestObj = object
|
||||
TestValue = object
|
||||
ThreadTestInt = (TestValue, )
|
||||
|
||||
@ -190,6 +192,10 @@ suite "Test ThreadDatastore cancelations":
|
||||
echo "destroy TestObj!"
|
||||
flag.store(true)
|
||||
|
||||
proc `=destroy`(obj: var FutTestObj) =
|
||||
echo "destroy FutTestObj!"
|
||||
futFreed.store(true)
|
||||
|
||||
proc wait(flag: var Atomic[bool]) =
|
||||
echo "wait for task to be ready..."
|
||||
defer: echo ""
|
||||
@ -211,6 +217,10 @@ suite "Test ThreadDatastore cancelations":
|
||||
|
||||
proc runTestTask() {.async.} =
|
||||
|
||||
let obj = FutTestObj()
|
||||
await sleepAsync(1.milliseconds)
|
||||
defer: echo "fut FutTestObj: ", obj
|
||||
|
||||
let ctx = newTaskCtx(ThreadTestInt, signal=signal)
|
||||
dispatchTask(sds, signal):
|
||||
sds.tp.spawn errorTestTask(ctx)
|
||||
@ -226,9 +236,12 @@ suite "Test ThreadDatastore cancelations":
|
||||
finally:
|
||||
echo "finish"
|
||||
check ready.load() == true
|
||||
GC_fullCollect()
|
||||
futFreed.wait()
|
||||
echo "future freed it's mem!"
|
||||
check futFreed.load() == true
|
||||
|
||||
ms.fire()
|
||||
GC_fullCollect()
|
||||
flag.wait()
|
||||
check flag.load() == true
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user