Skip to content

Commit b897881

Browse files
authored
Merge pull request #6240 from IntersectMBO/nb/interrupt_nodes
Interrupt cardano nodes when `cardano-testnet` gets interrupted
2 parents 7e045ab + 762577b commit b897881

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

cardano-testnet/cardano-testnet.cabal

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ common project-config
2828
-Wredundant-constraints
2929
-Wunused-packages
3030

31+
common maybe-unix
32+
if !os(windows)
33+
build-depends: unix
34+
3135
library
32-
import: project-config
36+
import: maybe-unix
37+
, project-config
3338

3439
build-depends: aeson
3540
, aeson-pretty
@@ -101,6 +106,7 @@ library
101106
Testnet.Defaults
102107
Testnet.EpochStateProcessing
103108
Testnet.Filepath
109+
Testnet.Handlers
104110
Testnet.Ping
105111
Testnet.Process.Cli.DRep
106112
Testnet.Process.Cli.Keys
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE NamedFieldPuns #-}
3+
4+
#if !defined(mingw32_HOST_OS)
5+
#define UNIX
6+
#endif
7+
8+
module Testnet.Handlers
9+
( interruptNodesOnSigINT
10+
) where
11+
12+
#ifdef UNIX
13+
import Control.Monad
14+
import System.Posix.Signals (Handler (..), installHandler, sigINT, raiseSignal)
15+
import System.Process (interruptProcessGroupOf)
16+
#endif
17+
18+
import Testnet.Types
19+
20+
interruptNodesOnSigINT :: [TestnetNode] -> IO ()
21+
#ifdef UNIX
22+
interruptNodesOnSigINT testnetNodes =
23+
-- Interrupt cardano nodes when the main process is interrupted
24+
void $ flip (installHandler sigINT) Nothing $ CatchOnce $ do
25+
forM_ testnetNodes $ \TestnetNode{nodeProcessHandle} ->
26+
interruptProcessGroupOf nodeProcessHandle
27+
raiseSignal sigINT
28+
#else
29+
interruptNodesOnSigINT _testnetNodes = pure ()
30+
#endif

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import qualified System.Info as OS
5252
import Testnet.Components.Configuration
5353
import qualified Testnet.Defaults as Defaults
5454
import Testnet.Filepath
55+
import Testnet.Handlers (interruptNodesOnSigINT)
5556
import Testnet.Process.Run (execCli', execCli_, mkExecConfig)
5657
import Testnet.Property.Assert (assertChainExtended, assertExpectedSposInLedgerState)
5758
import Testnet.Runtime as TR
@@ -299,6 +300,8 @@ cardanoTestnet
299300
H.noteShow_ . vsep $ prettyError <$> failedNodes
300301
H.failure
301302

303+
-- Interrupt cardano nodes when the main process is interrupted
304+
H.evalIO $ interruptNodesOnSigINT testnetNodes'
302305
H.annotateShow $ nodeSprocket <$> testnetNodes'
303306

304307
-- FIXME: use foldEpochState waiting for chain extensions

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SubmitApi/Transaction.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import qualified Hedgehog.Extras.Test.Golden as H
5151
import qualified Hedgehog.Extras.Test.TestWatchdog as H
5252

5353
-- | Execute me with:
54-
-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/transaction/"'@
54+
-- @DISABLE_RETRIES=1 cabal test cardano-testnet-test --test-options '-p "/SubmitApi.transaction/"'@
5555
hprop_transaction :: Property
5656
hprop_transaction = integrationRetryWorkspace 2 "submit-api-transaction" $ \tempAbsBasePath' -> H.runWithDefaultWatchdog_ $ do
5757
H.note_ SYS.os

0 commit comments

Comments
 (0)