Skip to content

Commit 1853eb4

Browse files
committed
testsuite: Add process-fork-wait test
1 parent 5a0cbd4 commit 1853eb4

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

tests/all.T

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ test('process010', normal, compile_and_run, [''])
3838
test('process011', when(opsys('mingw32'), skip), compile_and_run, [''])
3939

4040
test('T8343', normal, compile_and_run, [''])
41+
test('process-fork-wait', normal, compile_and_run, [''])

tests/process-fork-wait.hs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- | This test verifies that the 'use_process_jobs' feature works as
2+
-- advertised. Specifically: on Windows 'waitForProcess' should not return
3+
-- until all processes created by the child (including those created with
4+
-- @fork@) have exited if 'use_process_jobs' is enabled.
5+
--
6+
7+
module Main where
8+
9+
import Control.Concurrent
10+
import Control.Monad
11+
import System.Environment
12+
import System.IO
13+
import System.Process
14+
15+
main :: IO ()
16+
main = do
17+
args <- getArgs
18+
run args
19+
20+
run :: [String] -> IO ()
21+
run [] = do
22+
putStrLn "starting A"
23+
hFlush stdout
24+
(_,_,_,p) <- createProcess $ (proc "process-fork-wait" ["A"]) { use_process_jobs = True }
25+
void $ waitForProcess p
26+
contents <- readFile "test"
27+
when (contents /= "looks good to me")
28+
$ fail "invalid file contents"
29+
run ["A"] = do
30+
putStrLn "A started"
31+
hFlush stdout
32+
(_,_,_,_) <- createProcess $ (proc "process-fork-wait" ["B"])
33+
return ()
34+
run ["B"] = do
35+
putStrLn "B started"
36+
hFlush stdout
37+
threadDelay (5*1000*1000)
38+
writeFile "test" "looks good to me"
39+
putStrLn "B finished"
40+
run _ = fail "unknown mode"

tests/process-fork-wait.stdout

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
starting A
2+
A started
3+
B started
4+
B finished

0 commit comments

Comments
 (0)