nim-chronos/chronos/unittest2/asynctests.nim

33 lines
842 B
Nim
Raw Normal View History

#
# Chronos Unittest2 Helpers
# (c) Copyright 2022-Present
# Status Research & Development GmbH
#
# Licensed under either of
# Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT)
import std/tables
import unittest2
import ../../chronos
export unittest2, chronos
template asyncTest*(name: string, body: untyped): untyped =
test name:
waitFor((
proc() {.async, gcsafe.} =
body
)())
template checkLeaks*(name: string): untyped =
let counter = getTrackerCounter(name)
2023-09-05 10:41:52 +00:00
checkpoint:
"[" & name & "] opened = " & $counter.opened &
", closed = " & $ counter.closed
check counter.opened == counter.closed
2024-01-18 12:34:16 +00:00
proc checkLeaks*() =
for key in getThreadDispatcher().trackerCounterKeys():
checkLeaks(key)
2024-01-18 12:34:16 +00:00
GC_fullCollect()