Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, [''])
42 changes: 42 additions & 0 deletions tests/process-fork-wait.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- | 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
-- Disabling use_process_jobs here will cause waitForProcess to return
-- before the process B invocation has written the test file.
(_,_,_,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