Skip to content

Commit

Permalink
Merge pull request #1346 from input-output-hk/smoke-test-traces
Browse files Browse the repository at this point in the history
Small smoke test fixes
  • Loading branch information
v0d1ch authored Mar 12, 2024
2 parents cf5223e + 6a6c1ca commit 34d2890
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/smoke-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ jobs:
if ${{inputs.use-mithril}}; then
USE_MITHRIL_ARG="--use-mithril"
fi
# In case we run against an already running node, fix the permissions of
# the host-mounted node.socket file (which would be owned by root)
if [ -e ${state_dir}/node.socket ]; then
sudo chmod a+w ${state_dir}/node.socket
fi
nix develop .#exes --command bash -c "hydra-cluster --${{inputs.network}} --state-directory ${state_dir} ${HYDRA_SCRIPTS_ARG} ${USE_MITHRIL_ARG}"
- name: 💾 Upload logs
Expand Down
3 changes: 2 additions & 1 deletion hydra-cluster/exe/hydra-cluster/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ main =
run :: Options -> IO ()
run options =
withTracer (Verbose "hydra-cluster") $ \tracer -> do
traceWith tracer ClusterOptions{options}
let fromCardanoNode = contramap FromCardanoNode tracer
withStateDirectory $ \workDir ->
case knownNetwork of
Expand All @@ -39,7 +40,7 @@ run options =
Options{knownNetwork, stateDirectory, publishHydraScripts, useMithril} = options

withRunningCardanoNode tracer workDir network action =
findRunningCardanoNode workDir network >>= \case
findRunningCardanoNode (contramap FromCardanoNode tracer) workDir network >>= \case
Just node ->
action node
Nothing -> do
Expand Down
9 changes: 5 additions & 4 deletions hydra-cluster/src/CardanoNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ data NodeLog
| MsgNodeStarting {stateDirectory :: FilePath}
| MsgSocketIsReady SocketPath
| MsgSynchronizing {percentDone :: Centi}
| MsgQueryGenesisParametersFailed {err :: Text}
deriving stock (Eq, Show, Generic)
deriving anyclass (ToJSON, FromJSON)

Expand Down Expand Up @@ -129,11 +130,11 @@ getCardanoNodeVersion =
-- | Tries to find an communicate with an existing cardano-node running in given
-- work directory. NOTE: This is using the default node socket name as defined
-- by 'defaultCardanoNodeArgs'.
findRunningCardanoNode :: FilePath -> KnownNetwork -> IO (Maybe RunningNode)
findRunningCardanoNode workDir knownNetwork = do
findRunningCardanoNode :: Tracer IO NodeLog -> FilePath -> KnownNetwork -> IO (Maybe RunningNode)
findRunningCardanoNode tracer workDir knownNetwork = do
try (queryGenesisParameters knownNetworkId socketPath QueryTip) >>= \case
Left (_ :: SomeException) ->
pure Nothing
Left (e :: SomeException) ->
traceWith tracer MsgQueryGenesisParametersFailed{err = show e} $> Nothing
Right GenesisParameters{protocolParamActiveSlotsCoefficient, protocolParamSlotLength} ->
pure $
Just
Expand Down
9 changes: 6 additions & 3 deletions hydra-cluster/src/Hydra/Cluster/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ data Options = Options
, publishHydraScripts :: PublishOrReuse
, useMithril :: UseMithril
}
deriving stock (Show)
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

data PublishOrReuse = Publish | Reuse TxId
deriving stock (Show)
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

data UseMithril = NotUseMithril | UseMithril
deriving stock (Show, Eq)
deriving stock (Show, Eq, Generic)
deriving anyclass (ToJSON, FromJSON)

parseOptions :: Parser Options
parseOptions =
Expand Down
4 changes: 3 additions & 1 deletion hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import Hydra.Cluster.Faucet (FaucetLog, createOutputAtAddress, seedFromFaucet, s
import Hydra.Cluster.Faucet qualified as Faucet
import Hydra.Cluster.Fixture (Actor (..), actorName, alice, aliceSk, aliceVk, bob, bobSk, bobVk, carol, carolSk)
import Hydra.Cluster.Mithril (MithrilLog)
import Hydra.Cluster.Options (Options)
import Hydra.Cluster.Util (chainConfigFor, keysFor, modifyConfig, setNetworkId)
import Hydra.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod), fromNominalDiffTime)
import Hydra.HeadId (HeadId)
Expand Down Expand Up @@ -101,7 +102,8 @@ import System.FilePath ((</>))
import Test.QuickCheck (generate)

data EndToEndLog
= FromCardanoNode NodeLog
= ClusterOptions {options :: Options}
| FromCardanoNode NodeLog
| FromFaucet FaucetLog
| FromHydraNode HydraNodeLog
| FromMithril MithrilLog
Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/test/Test/CardanoNodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ spec = do
describe "findRunningCardanoNode" $ do
it "returns Nothing on non-matching network" $ \(tr, tmp) -> do
withCardanoNodeOnKnownNetwork tr tmp Sanchonet $ \_ -> do
findRunningCardanoNode tmp Preproduction `shouldReturn` Nothing
findRunningCardanoNode tr tmp Preproduction `shouldReturn` Nothing

it "returns Just running node on matching network" $ \(tr, tmp) -> do
withCardanoNodeOnKnownNetwork tr tmp Sanchonet $ \runningNode -> do
findRunningCardanoNode tmp Sanchonet `shouldReturn` Just runningNode
findRunningCardanoNode tr tmp Sanchonet `shouldReturn` Just runningNode

setupTracerAndTempDir :: ToJSON msg => ((Tracer IO msg, FilePath) -> IO a) -> IO a
setupTracerAndTempDir action =
Expand Down

0 comments on commit 34d2890

Please sign in to comment.