Skip to content

Commit 2916537

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

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.Monad
10+
import Control.Concurrent
11+
import System.Process
12+
import System.Environment
13+
14+
main :: IO ()
15+
main = do
16+
args <- getArgs
17+
run args
18+
19+
run :: [String] -> IO ()
20+
run [] = do
21+
putStrLn "starting A"
22+
(_,_,_,p) <- createProcess $ (proc "process-fork-wait" ["A"]) { use_process_jobs = True }
23+
void $ waitForProcess p
24+
contents <- readFile "test"
25+
when (contents /= "looks good to me")
26+
$ fail "invalid file contents"
27+
run ["A"] = do
28+
putStrLn "A started"
29+
(_,_,_,_) <- createProcess $ (proc "process-fork-wait" ["B"])
30+
return ()
31+
run ["B"] = do
32+
putStrLn "B started"
33+
threadDelay (5*1000*1000)
34+
writeFile "test" "looks good to me"
35+
putStrLn "B finished"
36+
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+
A started
2+
B started
3+
B finished
4+
starting A

0 commit comments

Comments
 (0)