Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression test 38 #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 src/System/Process/Typed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ startProcess pConfig'@ProcessConfig {..} = liftIO $ do
-- then call waitForProcess ourselves
Left _ -> do
eres <- try $ P.terminateProcess pHandle
P.getProcessExitCode pHandle
ec <-
case eres of
Left e
Expand Down
17 changes: 17 additions & 0 deletions test/System/Process/TypedSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import System.Process.Typed.Internal
import System.IO
import Control.Concurrent.Async (Concurrently (..))
import Control.Concurrent.STM (atomically)
import Control.Monad (when, replicateM_)
import Test.Hspec
import System.Exit
import System.IO.Temp
Expand Down Expand Up @@ -121,6 +122,22 @@ spec = do
it "succeeds with sleep"
((withProcessWait_ (proc "sleep" ["1"]) $ const $ pure ()) :: IO ())

-- See https://github.com/fpco/typed-process/issues/38
describe "withProcessTerm" $ do
let iterations = 200
it "does not exhibit a race condition" $ do
replicateM_ iterations $ do
withProcessTerm (setStdin createPipe $ setStdout createPipe $ setStderr inherit $ proc "cat" []) $ \ph -> do
-- putStrLn $ "Iteration: " <> show i
let inHandle = getStdin ph
let outHandle = getStdout ph
let contents = "Hello world\n"
S.hPut inHandle contents
hFlush inHandle
output <- S.hGet outHandle (S.length contents)
when (output /= contents) $ fail "failed to read."


-- These tests fail on older GHCs/process package versions
-- because, apparently, waitForProcess isn't interruptible. See
-- https://github.com/fpco/typed-process/pull/26#issuecomment-505702573.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found this comment. I looks like it might be relevant.

Expand Down