commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
4k stars 843 forks source link

stack test fails to run clean up actions on SIGINT #6236

Open brandonchinn178 opened 1 year ago

brandonchinn178 commented 1 year ago

General summary/comments (optional)

Copied from https://github.com/UnkindPartition/tasty/issues/354

Steps to reproduce

-- foo.cabal
cabal-version: 3.0
name: foo
version: 0
build-type: Simple
test-suite tests
  main-is: foo.hs
  type: exitcode-stdio-1.0
  build-depends: base, tasty, tasty-hunit
import Control.Concurrent
import Control.Exception
import Test.Tasty
import Test.Tasty.HUnit

main :: IO ()
main = defaultMain $
  testCase "test" $ do
    putStrLn "Sleeping..."
    threadDelay 100000000 `finally`
      ( do
          putStrLn "finally.1"
          threadDelay 1000000
          putStrLn "finally.2"
      )
  1. Run stack test
  2. Ctrl-C after seeing "Sleeping..."

Expected

Should show the output

test: Sleeping...
finally.1
finally.2
tests: SignalException 15

Actual

Got output

test: Sleeping...
finally.1
tests: SignalException 15

Stack version

stack --version
Version 2.11.1, Git revision c1167a6abc3f4978ccded5ba0246a57387da0e2f x86_64 hpack-0.35.2

Method of installation

Platform

MacOS M2 arm

sol commented 1 year ago

This is likely due to https://github.com/fpco/typed-process/issues/73.

mpilgrem commented 1 year ago

@brandonchinn178, this may be operating system-specific. On Windows 11, I get (whether it is run as an executable or run as a test):

Sleeping...
test: finally.1
finally.2

For some reason (EDIT: garbled output is expected - see https://github.com/UnkindPartition/tasty#faq), the Sleeping... gets output before the test: - and Ctrl+C ends things silently.

mpilgrem commented 1 year ago

Based on this part of Stack.Build.Execute.singleTest, I think Stack itself just runs the test executable as a RIO.Process.proc - which is built on System.Process.Typed.proc from the typed-process package (as identified by @sol above):

mec <- withWorkingDir (toFilePath pkgDir) $
  optionalTimeout $ proc (toFilePath exePath) args $ \pc0 -> do
...

So, I do think this is an upstream issue.