osproc: added a better version of waitForExit for Haiku (#13938)
Also modified tosprocterminate to verify waitForExit implementations.
This commit is contained in:
parent
cc3f5d21b2
commit
5f6962337d
2 changed files with 83 additions and 6 deletions
|
|
@ -1,8 +1,10 @@
|
|||
discard """
|
||||
outputsub: "SUCCESS"
|
||||
cmd: "nim $target $options -r $file"
|
||||
targets: "c cpp"
|
||||
matrix: "--threads:on; "
|
||||
"""
|
||||
|
||||
import os, osproc
|
||||
import os, osproc, times, std / monotimes
|
||||
|
||||
when defined(Windows):
|
||||
const ProgramWhichDoesNotEnd = "notepad"
|
||||
|
|
@ -19,7 +21,21 @@ while process.running() and TimeToWait > 0:
|
|||
sleep(100)
|
||||
TimeToWait = TimeToWait - 100
|
||||
|
||||
if process.running():
|
||||
echo("FAILED")
|
||||
else:
|
||||
echo("SUCCESS")
|
||||
doAssert not process.running()
|
||||
echo("stopped process")
|
||||
|
||||
process.close()
|
||||
|
||||
echo("starting " & ProgramWhichDoesNotEnd)
|
||||
process = startProcess(ProgramWhichDoesNotEnd)
|
||||
echo("process should be stopped after 2s")
|
||||
|
||||
let start = getMonoTime()
|
||||
discard process.waitForExit(2000)
|
||||
let took = getMonoTime() - start
|
||||
|
||||
doAssert not process.running()
|
||||
# some additional time to account for overhead
|
||||
doAssert took < initDuration(seconds = 3)
|
||||
|
||||
echo("stopped process after ", took)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue