Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jun 11, 2020
1 parent 659f53d commit 638d8cf
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tests/async/tioselectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,41 @@ when not defined(windows):
result = true

when ioselSupportedPlatform:
proc timer_notification_test(): bool =
type TestData = object
s1, s2, s3, s4: int
proc timer_notification_test_impl(data: var TestData) =
var selector = newSelector[int]()
let t0 = 20
var timer = selector.registerTimer(t0, false, 0)
let t = 100
let t = 500
# values too close to `t0` cause the test to be flaky in CI on OSX+freebsd
# When running locally, t0=100, t=98 will succeed some of the time which indicates
# there is some lag involved. Note that the higher `t-t0` is, the less times
# the test fails.
var rc1 = selector.select(t)
var rc2 = selector.select(t)
assert len(rc1) == 1 and len(rc2) == 1, $(len(rc1), len(rc2))
assert len(rc1) <= 1 and len(rc2) <= 1
data.s1 += ord(len(rc1) == 1)
data.s2 += ord(len(rc2) == 1)
selector.unregister(timer)
discard selector.select(0)
selector.registerTimer(t0, true, 0)
let t2 = 50
let t2 = 100
# same comment as above
var rc4 = selector.select(t2)
var rc5 = selector.select(t2)
assert len(rc4) + len(rc5) == 1, $(len(rc4), len(rc5))
assert len(rc4) + len(rc5) <= 1
data.s3 += ord(len(rc4) == 1)
data.s4 += ord(len(rc5) == 0)
assert(selector.isEmpty())
selector.close()

proc timer_notification_test(): bool =
var data: TestData
let n = 20
for i in 0..<n:
timer_notification_test_impl(data)
doAssert data.s1 == n and data.s2 == n and data.s3 == n and data.s4 == n, $data
result = true

proc process_notification_test(): bool =
Expand Down Expand Up @@ -469,8 +482,7 @@ when not defined(windows):
processTest("Multithreaded user event notification test...",
mt_event_test())
when ioselSupportedPlatform:
for i in 0..<20:
processTest("Timer notification test...", timer_notification_test())
processTest("Timer notification test...", timer_notification_test())
processTest("Process notification test...", process_notification_test())
processTest("Signal notification test...", signal_notification_test())
when defined(macosx) or defined(freebsd) or defined(openbsd) or
Expand Down

0 comments on commit 638d8cf

Please sign in to comment.