Skip to content

Commit 4603acd

Browse files
committed
test CmdRun/Terminate: add some debug logging
We've seen some instability in the test, compare #8416 This adds timestamped output to make it easier to see what goes wrong in case the test fails again.
1 parent c57002a commit 4603acd

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

cabal-testsuite/PackageTests/NewBuild/CmdRun/Terminate/Main.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import Control.Concurrent (killThread, threadDelay, myThreadId)
22
import Control.Exception (finally)
33
import qualified System.Posix.Signals as Signal
44
import System.Exit (exitFailure)
5+
import qualified Data.Time.Clock as Time
6+
import qualified Data.Time.Format as Time
57

68
main = do
9+
-- timestamped logging to aid with #8416
10+
let log msg = do
11+
ts <- Time.getCurrentTime
12+
let tsfmt = Time.formatTime Time.defaultTimeLocale "%H:%M:%S.%q" ts
13+
putStrLn $ tsfmt <> " [exe ] " <> msg
714
mainThreadId <- myThreadId
815
Signal.installHandler Signal.sigTERM (Signal.Catch $ killThread mainThreadId) Nothing
916
(do
10-
putStrLn "about to sleep"
17+
log "about to write file"
1118
writeFile "exe.run" "up and running"
19+
log "about to sleep"
1220
threadDelay 10000000 -- 10s
13-
putStrLn "done sleeping")
14-
`finally` putStrLn "exiting"
21+
log "done sleeping")
22+
`finally` log "exiting"

cabal-testsuite/PackageTests/NewBuild/CmdRun/Terminate/RunKill.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ cabal-version: >= 1.10
55

66
executable exe
77
default-language: Haskell2010
8-
build-depends: base, process, unix
8+
build-depends: base, process, time, unix
99
main-is: Main.hs

cabal-testsuite/PackageTests/NewBuild/CmdRun/Terminate/cabal.test.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Control.Concurrent (threadDelay)
44
import System.Directory (removeFile)
55
import Control.Exception (catch, throwIO)
66
import System.IO.Error (isDoesNotExistError)
7+
import qualified Data.Time.Clock as Time
8+
import qualified Data.Time.Format as Time
79

810
{-
911
This test verifies that 'cabal run' terminates its
@@ -18,16 +20,28 @@ main :: IO ()
1820
main = cabalTest $ do
1921
skipIfWindows -- test project relies on Posix
2022

23+
-- timestamped logging to aid with #8416
24+
let logIO msg = do
25+
ts <- Time.getCurrentTime
26+
let tsfmt = Time.formatTime Time.defaultTimeLocale "%H:%M:%S.%q" ts
27+
putStrLn $ tsfmt <> " [cabal.test] " <> msg
28+
log = liftIO . logIO
29+
2130
dir <- fmap testCurrentDir getTestEnv
2231
let runFile = dir </> "exe.run"
2332
liftIO $ removeFile runFile `catchNoExist` return ()
2433

34+
log "about to v2-build"
2535
cabal_raw_action ["v2-build", "exe"] (\_ -> return ())
36+
log "about to v2-run"
2637
r <- fails $ cabal_raw_action ["v2-run", "exe"] $ \cabalHandle -> do
2738
-- wait for "cabal run" to have started "exe"
39+
logIO "about to wait for file"
2840
waitFile total runFile
2941
-- then kill "cabal run"
42+
logIO "about to terminate cabal"
3043
Process.terminateProcess cabalHandle
44+
log "v2-run done"
3145

3246
-- "exe" should exit, and should have been interrupted before
3347
-- finishing its sleep

0 commit comments

Comments
 (0)