summary refs log tree commit diff stats
path: root/tests/osproc
diff options
context:
space:
mode:
authorMark Leyva <maleyva1@users.noreply.github.com>2024-07-12 06:25:18 -0700
committerGitHub <noreply@github.com>2024-07-12 15:25:18 +0200
commit58b36bd85e271bb25e374c0266cf20dfd0ae9ef4 (patch)
tree138fda31679f95d68235eb8d6a04cd0f0c739f9a /tests/osproc
parent6d7ab08dee6aa7bb328b79f0f9e841d42788a646 (diff)
downloadNim-58b36bd85e271bb25e374c0266cf20dfd0ae9ef4.tar.gz
fixes #23825; Busy wait on waitid, sleeping at regular intervals (#23826)
Addresses #23825 by using the approaching described in
https://github.com/nim-lang/Nim/pull/23743#issuecomment-2199523110.

This takes the approach from Python's `subprocess` library which calls
`waitid` in loop, while sleeping at regular intervals.

CC @alex65536
Diffstat (limited to 'tests/osproc')
-rw-r--r--tests/osproc/twaitforexit.nim17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/osproc/twaitforexit.nim b/tests/osproc/twaitforexit.nim
index 5db8d2566..67caa4165 100644
--- a/tests/osproc/twaitforexit.nim
+++ b/tests/osproc/twaitforexit.nim
@@ -15,4 +15,19 @@ block: # bug #5091
             discard
 
         # check that we don't have to wait msWait milliseconds
-        doAssert(getTime() <  atStart + milliseconds(msWait))
\ No newline at end of file
+        doAssert(getTime() <  atStart + milliseconds(msWait))
+
+block: # bug #23825
+    var thr: array[0..99, Thread[int]]
+
+    proc threadFunc(i: int) {.thread.} =
+        let sleepTime = float(i) / float(thr.len + 1)
+        doAssert sleepTime < 1.0
+        let p = startProcess("sleep", workingDir = "", args = @[$sleepTime], options = {poUsePath, poParentStreams})
+        # timeout = 1_000_000 seconds ~= 278 hours ~= 11.5 days
+        doAssert p.waitForExit(timeout=1_000_000_000) == 0
+
+    for i in low(thr)..high(thr):
+        createThread(thr[i], threadFunc, i)
+
+    joinThreads(thr)