From 47fd3ba61fbbbfe40c4a8e804b88e0665f877bae Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Thu, 28 Sep 2023 14:57:20 -0700 Subject: [PATCH] test task cancel --- tests/datastore/testthreadproxyds.nim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/datastore/testthreadproxyds.nim b/tests/datastore/testthreadproxyds.nim index c7f825d..8a20fd4 100644 --- a/tests/datastore/testthreadproxyds.nim +++ b/tests/datastore/testthreadproxyds.nim @@ -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