From fe34031f130d7ad07e606610cd03b4cad3cf63b0 Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Wed, 22 May 2024 15:13:07 +0000 Subject: [PATCH] Denote supportedNetworks in hydra-cluster tests --- .github/workflows/check-tutorial.yaml | 2 +- hydra-cluster/test/Test/CardanoNodeSpec.hs | 47 +++++++++++++++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check-tutorial.yaml b/.github/workflows/check-tutorial.yaml index 8ea361cfcc5..11722d8904d 100644 --- a/.github/workflows/check-tutorial.yaml +++ b/.github/workflows/check-tutorial.yaml @@ -35,7 +35,7 @@ jobs: with open("hydra-cluster/test/Test/CardanoNodeSpec.hs", "r") as cardanoNodeSpecFile: body = cardanoNodeSpecFile.read() - expectedCardanoNodeVersion = re.findall(r"getCardanoNodeVersion.*([0-9]+\.[0-9]+\.[0-9]+)", body)[0] + expectedCardanoNodeVersion = re.findall(r"supportedCardanoNodeVersion.*([0-9]+\.[0-9]+\.[0-9]+)", body)[0] print("Checking used cardano-node version") if all(v == expectedCardanoNodeVersion for v in usedCardanoNodeVersions): diff --git a/hydra-cluster/test/Test/CardanoNodeSpec.hs b/hydra-cluster/test/Test/CardanoNodeSpec.hs index 970508038a7..04e029c3859 100644 --- a/hydra-cluster/test/Test/CardanoNodeSpec.hs +++ b/hydra-cluster/test/Test/CardanoNodeSpec.hs @@ -17,13 +17,40 @@ import Hydra.Logging (Tracer, showLogsOnFailure) import System.Directory (doesFileExist) import Test.Hydra.Cluster.Utils (forEachKnownNetwork) +supportedNetworks :: [KnownNetwork] +supportedNetworks = [Preview, Preproduction, Mainnet] + +-- Networks that start fast enough to run findRunningCardanoNode. +quickNetworks :: [KnownNetwork] +quickNetworks = [Sanchonet, Preview] + +supportedQuickNetworks :: [KnownNetwork] +supportedQuickNetworks = filter (`elem` quickNetworks) supportedNetworks + +supportedCardanoNodeVersion :: String +supportedCardanoNodeVersion = "8.9.0" + +forSupportedKnownNetworks :: String -> (KnownNetwork -> IO ()) -> Spec +forSupportedKnownNetworks msg action = forEachKnownNetwork msg $ \network -> do + unless (network `elem` supportedNetworks) $ + pendingWith $ + "cardano-node " <> supportedCardanoNodeVersion <> " is only supported on " ++ show supportedNetworks + action network + +forASupportedQuickNetwork :: String -> (KnownNetwork -> IO ()) -> Spec +forASupportedQuickNetwork msg action = + it msg $ + case supportedQuickNetworks of + (network : _) -> action network + _ -> pendingWith "No supported networks capable of running this test." + spec :: Spec spec = do -- NOTE: We also hard-code the cardano-node version here to allow prevent -- false positives test errors in case someone uses an "untested" / -- different than in shell.nix version of cardano-node and cardano-cli. it "has expected cardano-node version available" $ - getCardanoNodeVersion >>= (`shouldContain` "8.9.0") + getCardanoNodeVersion >>= (`shouldContain` supportedCardanoNodeVersion) around (failAfter 5 . setupTracerAndTempDir) $ do it "withCardanoNodeDevnet does start a block-producing devnet within 5 seconds" $ \(tr, tmp) -> @@ -39,18 +66,18 @@ spec = do slot2 <- queryTipSlotNo networkId nodeSocket slot2 `shouldSatisfy` (> slot1) - describe "findRunningCardanoNode" $ do - it "returns Nothing on non-matching network" $ \(tr, tmp) -> do - withCardanoNodeOnKnownNetwork tr tmp Preview $ \_ -> do + describe "findRunningCardanoNode" $ do + forASupportedQuickNetwork "returns Nothing on non-matching network" $ \network -> do + setupTracerAndTempDir $ \(tr, tmp) -> + withCardanoNodeOnKnownNetwork tr tmp network $ \_ -> do findRunningCardanoNode tr tmp Preproduction `shouldReturn` Nothing - it "returns Just running node on matching network" $ \(tr, tmp) -> do - withCardanoNodeOnKnownNetwork tr tmp Preview $ \runningNode -> do - findRunningCardanoNode tr tmp Preview `shouldReturn` Just runningNode + forASupportedQuickNetwork "returns Just running node on matching network" $ \network -> do + setupTracerAndTempDir $ \(tr, tmp) -> + withCardanoNodeOnKnownNetwork tr tmp network $ \runningNode -> do + findRunningCardanoNode tr tmp network `shouldReturn` Just runningNode - forEachKnownNetwork "withCardanoNodeOnKnownNetwork starts synchronizing within 10 seconds" $ \network -> do - when (network == Sanchonet) $ - pendingWith "cardano-node 8.9 not anymore supported on sanchonet" + forSupportedKnownNetworks "withCardanoNodeOnKnownNetwork starts synchronizing within 10 seconds" $ \network -> do -- NOTE: This implies that withCardanoNodeOnKnownNetwork does not -- synchronize the whole chain before continuing. setupTracerAndTempDir $ \(tr, tmp) ->