Skip to content

Commit 4bfb59c

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

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
-- Disabling use_process_jobs here will cause waitForProcess to return
25+
-- before the process B invocation has written the test file.
26+
(_,_,_,p) <- createProcess $ (proc "process-fork-wait" ["A"]) { use_process_jobs = True }
27+
void $ waitForProcess p
28+
contents <- readFile "test"
29+
when (contents /= "looks good to me")
30+
$ fail "invalid file contents"
31+
run ["A"] = do
32+
putStrLn "A started"
33+
hFlush stdout
34+
(_,_,_,_) <- createProcess $ (proc "process-fork-wait" ["B"])
35+
return ()
36+
run ["B"] = do
37+
putStrLn "B started"
38+
hFlush stdout
39+
threadDelay (5*1000*1000)
40+
writeFile "test" "looks good to me"
41+
putStrLn "B finished"
42+
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)