Skip to content

Commit

Permalink
testsuite: Add process-fork-wait test
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed May 31, 2020
1 parent 5a0cbd4 commit 1853eb4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/all.T
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ test('process010', normal, compile_and_run, [''])
test('process011', when(opsys('mingw32'), skip), compile_and_run, [''])

test('T8343', normal, compile_and_run, [''])
test('process-fork-wait', normal, compile_and_run, [''])
40 changes: 40 additions & 0 deletions tests/process-fork-wait.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- | This test verifies that the 'use_process_jobs' feature works as
-- advertised. Specifically: on Windows 'waitForProcess' should not return
-- until all processes created by the child (including those created with
-- @fork@) have exited if 'use_process_jobs' is enabled.
--

module Main where

import Control.Concurrent
import Control.Monad
import System.Environment
import System.IO
import System.Process

main :: IO ()
main = do
args <- getArgs
run args

run :: [String] -> IO ()
run [] = do
putStrLn "starting A"
hFlush stdout
(_,_,_,p) <- createProcess $ (proc "process-fork-wait" ["A"]) { use_process_jobs = True }
void $ waitForProcess p
contents <- readFile "test"
when (contents /= "looks good to me")
$ fail "invalid file contents"
run ["A"] = do
putStrLn "A started"
hFlush stdout
(_,_,_,_) <- createProcess $ (proc "process-fork-wait" ["B"])
return ()
run ["B"] = do
putStrLn "B started"
hFlush stdout
threadDelay (5*1000*1000)
writeFile "test" "looks good to me"
putStrLn "B finished"
run _ = fail "unknown mode"
4 changes: 4 additions & 0 deletions tests/process-fork-wait.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
starting A
A started
B started
B finished

0 comments on commit 1853eb4

Please sign in to comment.