Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spawn cardano-node in a test for 10 seconds.
- Loading branch information
Showing
8 changed files
with
116 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,5 @@ hie.yaml | |
|
||
# Ignore files generated by tests | ||
tmp | ||
/cardano-node/logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Test.Cardano.Node.Chairman | ||
( tests | ||
) where | ||
|
||
import Cardano.Prelude | ||
import Hedgehog (Property, discover) | ||
|
||
import qualified Hedgehog as H | ||
import qualified System.Process as IO | ||
import qualified Test.Common.Base as H | ||
import qualified Test.Common.Process as H | ||
|
||
prop_spawnOneNode :: Property | ||
prop_spawnOneNode = H.propertyOnce $ do | ||
(_mIn, _mOut, _mErr, hProcess) <- H.createProcess $ | ||
( IO.proc "cardano-node" | ||
[ "run" | ||
, "--database-path", "../db/node-2/" | ||
, "--socket-path", "../socket/node-2-socket" | ||
, "--port", "3002" | ||
, "--topology", "../configuration/defaults/simpleview/topology-node-2.json" | ||
, "--config", "../configuration/defaults/simpleview/config-2.yaml" | ||
, "--signing-key", "../configuration/defaults/simpleview/genesis/delegate-keys.002.key" | ||
, "--delegation-certificate", "../configuration/defaults/simpleview/genesis/delegation-cert.002.json" | ||
] | ||
) | ||
{ IO.create_group = True | ||
} | ||
|
||
H.threadDelay 10000000 | ||
|
||
H.interruptProcessGroupOf hProcess | ||
|
||
void $ H.waitForProcess hProcess | ||
|
||
tests :: IO Bool | ||
tests = H.checkParallel $$discover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Test.Common.Base | ||
( propertyOnce | ||
, threadDelay | ||
) where | ||
|
||
import Control.Monad.IO.Class (liftIO) | ||
import Data.Function (($), (.)) | ||
import Data.Int | ||
import System.IO (IO) | ||
|
||
import qualified Control.Concurrent as IO | ||
import qualified Hedgehog as H | ||
|
||
propertyOnce :: H.PropertyT IO () -> H.Property | ||
propertyOnce = H.withTests 1 . H.property | ||
|
||
threadDelay :: Int -> H.PropertyT IO () | ||
threadDelay n = liftIO $ IO.threadDelay n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Test.Common.Process | ||
( createProcess | ||
, interruptProcessGroupOf | ||
, waitForProcess | ||
) where | ||
|
||
import Control.Monad.IO.Class | ||
import Data.Function ((.)) | ||
import Data.Function (($)) | ||
import Data.Maybe (Maybe (..)) | ||
import GHC.Stack (HasCallStack) | ||
import System.Exit (ExitCode) | ||
import System.IO (Handle, IO) | ||
import System.Process (CreateProcess (..), ProcessHandle) | ||
|
||
import qualified GHC.Stack as GHC | ||
import qualified Hedgehog as H | ||
import qualified System.Process as IO | ||
|
||
createProcess :: HasCallStack | ||
=> CreateProcess | ||
-> H.PropertyT IO (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle) | ||
createProcess cp = GHC.withFrozenCallStack $ do | ||
H.evalM . liftIO $ IO.createProcess cp | ||
|
||
interruptProcessGroupOf :: HasCallStack | ||
=> ProcessHandle | ||
-> H.PropertyT IO () | ||
interruptProcessGroupOf hProcess = GHC.withFrozenCallStack $ do | ||
H.evalM . liftIO $ IO.interruptProcessGroupOf hProcess | ||
|
||
waitForProcess :: HasCallStack | ||
=> ProcessHandle | ||
-> H.PropertyT IO ExitCode | ||
waitForProcess hProcess = GHC.withFrozenCallStack $ do | ||
H.evalM . liftIO $ IO.waitForProcess hProcess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters