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

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

Open
brandonchinn178 opened this issue Sep 13, 2023 · 3 comments
Open

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

brandonchinn178 opened this issue Sep 13, 2023 · 3 comments

Comments

@brandonchinn178
Copy link

General summary/comments (optional)

Copied from UnkindPartition/tasty#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

  • GHCup

Platform

MacOS M2 arm

@sol
Copy link
Contributor

sol commented Sep 13, 2023

This is likely due to fpco/typed-process#73.

@mpilgrem
Copy link
Member

mpilgrem commented Sep 13, 2023

@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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants