Skip to content

Commit 18e3ae8

Browse files
author
Tom Sydney Kerckhove
committed
Regression test for fpco#38
1 parent e3efb3d commit 18e3ae8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/System/Process/TypedSpec.hs

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import System.Process.Typed.Internal
77
import System.IO
88
import Control.Concurrent.Async (Concurrently (..))
99
import Control.Concurrent.STM (atomically)
10+
import Control.Monad (when, replicateM_)
1011
import Test.Hspec
1112
import System.Exit
1213
import System.IO.Temp
@@ -121,6 +122,22 @@ spec = do
121122
it "succeeds with sleep"
122123
((withProcessWait_ (proc "sleep" ["1"]) $ const $ pure ()) :: IO ())
123124

125+
-- See https://github.com/fpco/typed-process/issues/38
126+
describe "withProcessTerm" $ do
127+
let iterations = 200
128+
it "does not exhibit a race condition" $ do
129+
replicateM_ iterations $ do
130+
withProcessTerm (setStdin createPipe $ setStdout createPipe $ setStderr inherit $ proc "cat" []) $ \ph -> do
131+
-- putStrLn $ "Iteration: " <> show i
132+
let inHandle = getStdin ph
133+
let outHandle = getStdout ph
134+
let contents = "Hello world\n"
135+
S.hPut inHandle contents
136+
hFlush inHandle
137+
output <- S.hGet outHandle (S.length contents)
138+
when (output /= contents) $ fail "failed to read."
139+
140+
124141
-- These tests fail on older GHCs/process package versions
125142
-- because, apparently, waitForProcess isn't interruptible. See
126143
-- https://github.com/fpco/typed-process/pull/26#issuecomment-505702573.

0 commit comments

Comments
 (0)