Files
Nim/tests/stdlib/tchannels.nim
Timothee Cour 4e0f38fbb1 testament :show duration also for failed tests; improve tshould_not_work; mitigate #17946 tchannels timeouts (#17947)
* refs #17946; refactor testament test summary, show test duration for failures; increase timeout tchannels

* revert workarounds from https://github.com/nim-lang/Nim/pull/16698 and add allowPrefixMatch optional param to greedyOrderedSubsetLines

* add test

* workaround for yet another testament bug
2021-05-08 17:13:47 +02:00

34 lines
951 B
Nim

discard """
timeout: 20.0 # but typically < 1s (in isolation but other tests running in parallel can affect this since based on epochTime)
disabled: "freebsd"
matrix: "--gc:arc --threads:on; --gc:arc --threads:on -d:danger"
"""
when true:
# bug #17380: this was either blocking (without -d:danger) or crashing with SIGSEGV (with -d:danger)
import std/[channels, isolation]
const
N1 = 10
N2 = 100
var
sender: array[N1, Thread[void]]
receiver: array[5, Thread[void]]
var chan = newChannel[seq[string]](N1 * N2) # large enough to not block
proc sendHandler() =
chan.send(isolate(@["Hello, Nim"]))
proc recvHandler() =
template fn =
let x = chan.recv()
fn()
template benchmark() =
for t in mitems(sender):
t.createThread(sendHandler)
joinThreads(sender)
for t in mitems(receiver):
t.createThread(recvHandler)
joinThreads(receiver)
for i in 0..<N2:
benchmark()