Skip to content

Commit

Permalink
Merge #2412
Browse files Browse the repository at this point in the history
2412: Fix signal handling in test cluster and integration tests r=rvl a=rvl

### Overview

This lets the test cluster and integration tests clean up properly if they are killed with SIGTERM.

### Comments

Based on PR #2409 branch - merge that first.

Co-authored-by: Rodney Lorrimar <[email protected]>
  • Loading branch information
iohk-bors[bot] and rvl authored Jan 4, 2021
2 parents a256c3e + efa193f commit 6194a93
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/launcher/src/Cardano/Startup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Cardano.Startup
, withShutdownHandler
, withShutdownHandler'
, installSignalHandlers
, installSignalHandlersNoLogging
, killProcess

-- * File permissions
Expand Down Expand Up @@ -155,3 +156,10 @@ instance HasSeverityAnnotation ShutdownHandlerLog where
MsgShutdownHandler _ -> Debug
MsgShutdownEOF -> Notice
MsgShutdownError _ -> Error

{-------------------------------------------------------------------------------
Termination Signal Handling
-------------------------------------------------------------------------------}

installSignalHandlersNoLogging :: IO ()
installSignalHandlersNoLogging = installSignalHandlers (pure ())
5 changes: 4 additions & 1 deletion lib/shelley/exe/shelley-test-cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Cardano.CLI
, withLoggingNamed
)
import Cardano.Startup
( setDefaultFilePermissions, withUtf8Encoding )
( installSignalHandlers, setDefaultFilePermissions, withUtf8Encoding )
import Cardano.Wallet.Api.Types
( EncodeAddress (..) )
import Cardano.Wallet.Logging
Expand Down Expand Up @@ -265,6 +265,9 @@ withLocalClusterSetup
:: (FilePath -> [LogOutput] -> [LogOutput] -> IO a)
-> IO a
withLocalClusterSetup action = do
-- Handle SIGTERM properly
installSignalHandlers (putStrLn "Terminated")

-- Ensure key files have correct permissions for cardano-cli
setDefaultFilePermissions

Expand Down
7 changes: 6 additions & 1 deletion lib/shelley/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import Cardano.CLI
import Cardano.Launcher
( ProcessHasExited (..) )
import Cardano.Startup
( setDefaultFilePermissions, withUtf8Encoding )
( installSignalHandlersNoLogging
, setDefaultFilePermissions
, withUtf8Encoding
)
import Cardano.Wallet.Api.Server
( Listen (..) )
import Cardano.Wallet.Api.Types
Expand Down Expand Up @@ -198,6 +201,8 @@ main = withTestsSetup $ \testDir tracers -> do
-- directory, and pass this info to the main hspec action.
withTestsSetup :: (FilePath -> (Tracer IO TestsLog, Tracers IO) -> IO a) -> IO a
withTestsSetup action = do
-- Handle SIGTERM properly
installSignalHandlersNoLogging
-- Flush test output as soon as a line is printed
hSetBuffering stdout LineBuffering
hSetBuffering stderr LineBuffering
Expand Down

0 comments on commit 6194a93

Please sign in to comment.