apatheia/tests/exampleGcFailures/exNoFailureNoGcCollectSeq.nim

40 lines
969 B
Nim
Raw Normal View History

2024-03-20 13:46:53 +02:00
import std/os
import chronos
import chronos/threadsync
import chronos/unittest2/asynctests
import taskpools
2024-03-20 14:04:18 +02:00
proc worker(data: string, sig: ThreadSignalPtr) =
2024-03-20 13:46:53 +02:00
os.sleep(4_000)
echo "running worker: "
echo "worker: ", data
discard sig.fireSync()
proc runTest(tp: TaskPool, sig: ThreadSignalPtr) {.async.} =
## init
2024-03-20 14:04:18 +02:00
var obj = "hello world!"
# obj.shallow()
2024-03-20 13:46:53 +02:00
echo "spawn worker"
tp.spawn worker(obj, sig)
## adding fut.wait(100.milliseconds) creates memory issue
await wait(sig).wait(100.milliseconds)
## just doing the wait is fine:
# await wait(sig)
proc runTests(tp: TaskPool, sig: ThreadSignalPtr) {.async.} =
for i in 1..2_000:
try:
await runTest(tp, sig)
os.sleep(200)
except AsyncTimeoutError:
echo "looping..."
suite "async tests":
var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.
let sig = ThreadSignalPtr.new().get()
asyncTest "test":
await runTests(tp, sig)