Serialize writer submission and shutdown, enqueue explicit stop messages after accepted records, and finish the final file batch before joining. Keep drained process-wide channel storage until exit to avoid the Nim 2.2.10 Channel.close mutex teardown defect. Cover empty records, multiple destinations, joined producers, and concurrent shutdown. Include writer lifecycle sanitizer tests in nimble test and update usage documentation. Validation: all 32 unit tests, eight writer exit scenarios, and writer lifecycle ThreadSanitizer tests pass. The full suite retains the known configuration refresh, timestamp, and default allocator failures.
72 lines
3.0 KiB
Nim
72 lines
3.0 KiB
Nim
# Package
|
|
|
|
version = "3.0.0"
|
|
author = "Jonathan Bernard"
|
|
description = "Wrapper around std/logging to provide namespaced logging."
|
|
license = "MIT"
|
|
srcDir = "src"
|
|
|
|
|
|
# Dependencies
|
|
|
|
requires @["nim >= 2.2.0", "zero_functional"]
|
|
|
|
# from https://git.jdb-software.com/jdb/nim-packages
|
|
requires "timeutils"
|
|
|
|
proc runUnitTests() =
|
|
if fileExists("src/namespaced_logging.out"): rmFile("src/namespaced_logging.out")
|
|
exec "nimble c --mm:orc --threads:on src/namespaced_logging.nim"
|
|
if not fileExists("src/namespaced_logging.out"):
|
|
raise newException(OSError, "Unit test compilation produced no executable")
|
|
exec "src/namespaced_logging.out"
|
|
|
|
proc runRegressionTests() =
|
|
if fileExists("tests/bin/writer_child"): rmFile("tests/bin/writer_child")
|
|
if fileExists("tests/bin/regressions"): rmFile("tests/bin/regressions")
|
|
exec "nimble c --mm:orc --threads:on -d:multithreaded --out:tests/bin/writer_child tests/writer_child.nim"
|
|
if not fileExists("tests/bin/writer_child"):
|
|
raise newException(OSError, "Writer test compilation produced no executable")
|
|
exec "nimble c --mm:orc --threads:on --out:tests/bin/regressions tests/regressions.nim"
|
|
if not fileExists("tests/bin/regressions"):
|
|
raise newException(OSError, "Regression test compilation produced no executable")
|
|
exec "tests/bin/regressions"
|
|
|
|
proc runThreadSafetyTests() =
|
|
if fileExists("tests/bin/thread_safety"): rmFile("tests/bin/thread_safety")
|
|
if fileExists("tests/bin/writer_lifecycle"): rmFile("tests/bin/writer_lifecycle")
|
|
exec "nimble c --mm:orc --threads:on --passC:-fsanitize=thread --passC:-g --passL:-fsanitize=thread --out:tests/bin/thread_safety tests/thread_safety.nim"
|
|
if not fileExists("tests/bin/thread_safety"):
|
|
raise newException(OSError, "Thread-safety test compilation produced no executable")
|
|
exec "nimble c --mm:orc --threads:on --passC:-fsanitize=thread --passC:-g --passL:-fsanitize=thread --out:tests/bin/writer_lifecycle src/namespaced_logging.nim"
|
|
if not fileExists("tests/bin/writer_lifecycle"):
|
|
raise newException(OSError, "Writer lifecycle test compilation produced no executable")
|
|
exec "bash tests/run_tsan.sh tests/bin/thread_safety tests/bin/writer_lifecycle"
|
|
|
|
task test, "Run all tests, including ThreadSanitizer, and report all failing suites.":
|
|
var failedSuites: seq[string] = @[]
|
|
template runSuite(name: string, action: untyped) =
|
|
echo "Running test suite: ", name
|
|
try:
|
|
action
|
|
echo "PASS: ", name
|
|
except OSError as err:
|
|
echo "FAIL: ", name, ": ", err.msg
|
|
failedSuites.add(name)
|
|
|
|
runSuite("unit", runUnitTests())
|
|
runSuite("regression", runRegressionTests())
|
|
runSuite("thread safety", runThreadSafetyTests())
|
|
if failedSuites.len > 0:
|
|
echo "Failed test suites: ", failedSuites
|
|
quit(1)
|
|
|
|
task testUnit, "Run the existing embedded unit tests under ORC.":
|
|
runUnitTests()
|
|
|
|
task testRegression, "Run ownership, configuration, and shutdown regressions.":
|
|
runRegressionTests()
|
|
|
|
task testThreadSafety, "Run ORC ownership tests with ThreadSanitizer (Linux).":
|
|
runThreadSafetyTests()
|