File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import System.Process.Typed.Internal
7
7
import System.IO
8
8
import Control.Concurrent.Async (Concurrently (.. ))
9
9
import Control.Concurrent.STM (atomically )
10
+ import Control.Monad (when , replicateM_ )
10
11
import Test.Hspec
11
12
import System.Exit
12
13
import System.IO.Temp
@@ -121,6 +122,22 @@ spec = do
121
122
it " succeeds with sleep"
122
123
((withProcessWait_ (proc " sleep" [" 1" ]) $ const $ pure () ) :: IO () )
123
124
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
+
124
141
-- These tests fail on older GHCs/process package versions
125
142
-- because, apparently, waitForProcess isn't interruptible. See
126
143
-- https://github.com/fpco/typed-process/pull/26#issuecomment-505702573.
You can’t perform that action at this time.
0 commit comments