Skip to content

Commit

Permalink
New shutdown-ipc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jan 19, 2022
1 parent b83499e commit 991c2e4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
1 change: 0 additions & 1 deletion cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ library
, plutus-ledger-api
, prettyprinter
, scientific
, small-steps
, cardano-ledger-shelley
, small-steps
, stm
Expand Down
1 change: 0 additions & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ library
, prettyprinter
, cardano-ledger-shelley
, set-algebra
, small-steps
, split
, strict-containers
, text
Expand Down
2 changes: 2 additions & 0 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ test-suite cardano-testnet-tests
, hedgehog
, hedgehog-extras
, filepath
, process
, tasty
, tasty-hedgehog
, text
Expand All @@ -128,6 +129,7 @@ test-suite cardano-testnet-tests
Spec.Plutus.Direct.TxInLockingPlutus
Spec.Plutus.Script.TxInLockingPlutus
Spec.Plutus.SubmitApi.TxInLockingPlutus
Spec.Shutdown

ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T

Expand Down
2 changes: 2 additions & 0 deletions cardano-testnet/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import qualified Spec.Plutus.Direct.ScriptContextEqualityMint
import qualified Spec.Plutus.Direct.TxInLockingPlutus
import qualified Spec.Plutus.Script.TxInLockingPlutus
import qualified Spec.Plutus.SubmitApi.TxInLockingPlutus
import qualified Spec.Shutdown

tests :: IO TestTree
tests = do
Expand All @@ -34,6 +35,7 @@ tests = do
, H.testProperty "Spec.Plutus.SubmitApi.TxInLockingPlutus" Spec.Plutus.SubmitApi.TxInLockingPlutus.hprop_plutus
, ignoreOnWindows "Spec.Plutus.Direct.ScriptContextEquality" Spec.Plutus.Direct.ScriptContextEquality.hprop_plutus_script_context_equality
, ignoreOnWindows "Spec.Plutus.Direct.ScriptContextEqualityMint" Spec.Plutus.Direct.ScriptContextEqualityMint.hprop_plutus_script_context_mint_equality
, ignoreOnWindows "Spec.Shutdown" Spec.Shutdown.hprop_shutdown
]
]

Expand Down
89 changes: 89 additions & 0 deletions cardano-testnet/test/Spec/Shutdown.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}

module Spec.Shutdown
( hprop_shutdown
) where

import Control.Monad
import Data.Function
import Data.Functor ((<&>))
import Data.Int
import Data.Maybe
import GHC.Num
import Hedgehog (Property, (===))
import System.FilePath ((</>))
import Text.Show (Show (..))

import qualified Hedgehog as H
import qualified Hedgehog.Extras.Stock.IO.Network.Socket as IO
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.Concurrent as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Process as H
import qualified System.Directory as IO
import qualified System.Exit as IO
import qualified System.IO as IO
import qualified System.Process as IO
import qualified Test.Base as H
import qualified Test.Process as H
import qualified Testnet.Conf as H

{- HLINT ignore "Redundant <&>" -}
{- HLINT ignore "Redundant return" -}
{- HLINT ignore "Use let" -}

hprop_shutdown :: Property
hprop_shutdown = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsBasePath' -> do
projectBase <- H.note =<< H.noteIO . IO.canonicalizePath =<< H.getProjectBase
H.Conf { H.tempBaseAbsPath, H.tempAbsPath, H.logDir } <- H.noteShowM $ H.mkConf tempAbsBasePath' Nothing

[port] <- H.noteShowIO $ IO.allocateRandomPorts 1

H.createDirectoryIfMissing logDir

nodeStdoutFile <- H.noteTempFile logDir "node.stdout.log"
nodeStderrFile <- H.noteTempFile logDir "node.stderr.log"

hNodeStdout <- H.openFile nodeStdoutFile IO.WriteMode
hNodeStderr <- H.openFile nodeStderrFile IO.WriteMode

-- Run cardano-node with pipe as stdin. Use 0 file descriptor as shutdown-ipc
(mStdin, _mStdout, _mStderr, pHandle, _releaseKey) <- H.createProcess =<<
( H.procNode
[ "run"
, "--config", projectBase </> "configuration/cardano/mainnet-config.json"
, "--topology", projectBase </> "configuration/cardano/mainnet-topology.json"
, "--database-path", tempAbsPath </> "db"
, "--socket-path", tempAbsPath </> "node-1-socket"
, "--host-addr", "127.0.0.1"
, "--port", show @Int port
, "--shutdown-ipc", "0"
] <&>
( \cp -> cp
{ IO.std_in = IO.CreatePipe
, IO.std_out = IO.UseHandle hNodeStdout
, IO.std_err = IO.UseHandle hNodeStderr
, IO.cwd = Just tempBaseAbsPath
}
)
)

H.threadDelay $ 10 * 1000000

mExitCodeRunning <- H.evalIO $ IO.getProcessExitCode pHandle

mExitCodeRunning === Nothing

forM_ mStdin $ \hStdin -> H.evalIO $ IO.hClose hStdin

H.threadDelay $ 1 * 1000000

mExitCode <- H.evalIO $ IO.getProcessExitCode pHandle

mExitCode === Just IO.ExitSuccess

return ()

0 comments on commit 991c2e4

Please sign in to comment.