summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--testament/important_packages.nim3
-rw-r--r--tests/async/tioselectors.nim9
-rw-r--r--tests/m14634.nim48
3 files changed, 55 insertions, 5 deletions
diff --git a/testament/important_packages.nim b/testament/important_packages.nim
index 19e11e322..5a28fa3dd 100644
--- a/testament/important_packages.nim
+++ b/testament/important_packages.nim
@@ -40,7 +40,8 @@ pkg1 "delaunay"
 pkg1 "docopt"
 pkg1 "easygl", true, "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
 pkg1 "elvis"
-pkg1 "fidget", true, "nim c -d:release -r tests/runNative.nim"
+# pkg1 "fidget", true, "nim c -d:release -r tests/runNative.nim"
+  # Error: cannot open 'tests/runNative.nim'
 pkg1 "fragments", false, "nim c -r fragments/dsl.nim"
 pkg1 "gara"
 pkg1 "ggplotnim", true, "nim c -d:noCairo -r -d:nimWorkaround14447 tests/tests.nim"
diff --git a/tests/async/tioselectors.nim b/tests/async/tioselectors.nim
index c20df29e5..f7487525a 100644
--- a/tests/async/tioselectors.nim
+++ b/tests/async/tioselectors.nim
@@ -145,14 +145,15 @@ when not defined(windows):
     proc timer_notification_test(): bool =
       var selector = newSelector[int]()
       var timer = selector.registerTimer(100, false, 0)
-      var rc1 = selector.select(140)
-      var rc2 = selector.select(140)
+      var rc1 = selector.select(10000)
+      var rc2 = selector.select(10000)
+      # if this flakes, see tests/m14634.nim
       assert len(rc1) == 1 and len(rc2) == 1, $(len(rc1), len(rc2))
       selector.unregister(timer)
       discard selector.select(0)
       selector.registerTimer(100, true, 0)
-      var rc4 = selector.select(120)
-      var rc5 = selector.select(120)
+      var rc4 = selector.select(10000)
+      var rc5 = selector.select(1000) # this will be an actual wait, keep it small
       assert len(rc4) == 1 and len(rc5) == 0, $(len(rc4), len(rc5))
       assert(selector.isEmpty())
       selector.close()
diff --git a/tests/m14634.nim b/tests/m14634.nim
new file mode 100644
index 000000000..56a3d9034
--- /dev/null
+++ b/tests/m14634.nim
@@ -0,0 +1,48 @@
+#[
+Tool to investigate underlying reasons for https://github.com/nim-lang/Nim/pull/14634
+nim r --threads:on -d:threadsafe tests/m14634.nim
+]#
+
+when not defined(windows):
+  import std/selectors
+
+  type TestData = object
+    s1, s2, s3: int
+
+  proc timerNotificationTestImpl(data: var TestData) =
+    var selector = newSelector[int]()
+    let t0 = 5
+    var timer = selector.registerTimer(t0, false, 0)
+    let t = 2000
+      # 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
+    data.s1 += ord(len(rc1) == 1)
+    data.s2 += ord(len(rc2) == 1)
+    selector.unregister(timer)
+    discard selector.select(0)
+    selector.registerTimer(t0, true, 0)
+      # same comment as above
+    var rc4 = selector.select(t)
+    let t2 = 100
+      # this can't be too large as it'll actually wait that long:
+      # timer_notification_test.n * t2
+    var rc5 = selector.select(t2)
+    assert len(rc4) + len(rc5) <= 1
+    data.s3 += ord(len(rc4) + len(rc5) == 1)
+    assert(selector.isEmpty())
+    selector.close()
+
+  proc timerNotificationTest() =
+    var data: TestData
+    let n = 10
+    for i in 0..<n:
+      timerNotificationTestImpl(data)
+    doAssert data.s1 == n and data.s2 == n and data.s3 == n, $data
+
+  when isMainModule:
+    timerNotificationTest()