Skip to content

Commit

Permalink
Prevent tests from running concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Apr 3, 2024
1 parent 6c606d3 commit 350a5e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
3 changes: 2 additions & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ library
, filepath
, hedgehog
, hedgehog-extras < 0.6.2
, microlens
, lens-aeson
, lifted-base
, microlens
, mtl
, network
, network-mux
Expand Down
10 changes: 8 additions & 2 deletions cardano-testnet/src/Testnet/Property/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import Cardano.Chain.Genesis (GenesisHash (unGenesisHash), readGenesis
import qualified Cardano.Crypto.Hash.Blake2b as Crypto
import qualified Cardano.Crypto.Hash.Class as Crypto

import qualified Control.Concurrent.QSem as IO
import qualified Control.Exception.Lifted as CE
import Control.Exception.Safe (MonadCatch)
import Control.Monad
import Control.Monad.Trans.Resource
Expand All @@ -48,16 +50,20 @@ import qualified Hedgehog as H
import qualified Hedgehog.Extras as H
import Hedgehog.Internal.Property (MonadTest)


disableRetries :: Bool
disableRetries = IO.unsafePerformIO $ do
mValue <- IO.lookupEnv "DISABLE_RETRIES"
return $ mValue == Just "1"
{-# NOINLINE disableRetries #-}

sem :: IO.QSem
sem = IO.unsafePerformIO $ IO.newQSem 1
{-# NOINLINE sem #-}

-- TODO: Document what an Integration is
integration :: HasCallStack => H.Integration () -> H.Property
integration f = GHC.withFrozenCallStack $ H.withTests 1 $ H.propertyOnce f
integration f = GHC.withFrozenCallStack $ H.withTests 1 $ H.propertyOnce $
CE.bracket_ (liftIO $ IO.waitQSem sem) (liftIO $ IO.signalQSem sem) f

-- | The 'FilePath' in '(FilePath -> H.Integration ())' is the work space directory.
-- This is created (and returned) via 'H.workspace'.
Expand Down
33 changes: 10 additions & 23 deletions cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,36 @@ import qualified Test.Tasty.Ingredients as T

tests :: IO TestTree
tests = do
testGroup <- runTestGroup <$> shouldRunInParallel
pure $ testGroup "test/Spec.hs"
[ testGroup "Spec"
[ testGroup "Ledger Events"
pure $ T.testGroup "test/Spec.hs"
[ T.testGroup "Spec"
[ T.testGroup "Ledger Events"
[ H.ignoreOnWindows "Sanity Check" LedgerEvents.hprop_ledger_events_sanity_check
, H.ignoreOnWindows "Treasury Growth" LedgerEvents.prop_check_if_treasury_is_growing
-- TODO: Replace foldBlocks with checkLedgerStateCondition
, testGroup "Governance"
, T.testGroup "Governance"
[ H.ignoreOnMacAndWindows "ProposeAndRatifyNewConstitution" Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitution.hprop_ledger_events_propose_new_constitution
-- FIXME Those tests are flaky
-- , H.ignoreOnWindows "InfoAction" LedgerEvents.hprop_ledger_events_info_action
, H.ignoreOnWindows "ProposeNewConstitutionSPO" LedgerEvents.hprop_ledger_events_propose_new_constitution_spo
, H.ignoreOnWindows "DRepRetirement" DRepRetirement.hprop_drep_retirement
]
, testGroup "Plutus"
, T.testGroup "Plutus"
[ H.ignoreOnWindows "PlutusV3" Cardano.Testnet.Test.Cli.Conway.Plutus.hprop_plutus_v3]
]
, testGroup "CLI"
, T.testGroup "CLI"
[ H.ignoreOnWindows "Shutdown" Cardano.Testnet.Test.Node.Shutdown.hprop_shutdown
-- ShutdownOnSigint fails on Mac with
-- "Log file: /private/tmp/tmp.JqcjW7sLKS/kes-period-info-2-test-30c2d0d8eb042a37/logs/test-spo.stdout.log had no logs indicating the relevant node has minted blocks."
, H.ignoreOnMacAndWindows "ShutdownOnSigint" Cardano.Testnet.Test.Node.Shutdown.hprop_shutdownOnSigint
-- ShutdownOnSlotSynced FAILS Still. The node times out and it seems the "shutdown-on-slot-synced" flag does nothing
-- , H.ignoreOnWindows "ShutdownOnSlotSynced" Cardano.Testnet.Test.Node.Shutdown.hprop_shutdownOnSlotSynced
, testGroup "Babbage"
, T.testGroup "Babbage"
[ H.ignoreOnMacAndWindows "leadership-schedule" Cardano.Testnet.Test.Cli.Babbage.LeadershipSchedule.hprop_leadershipSchedule -- FAILS
, H.ignoreOnWindows "stake-snapshot" Cardano.Testnet.Test.Cli.Babbage.StakeSnapshot.hprop_stakeSnapshot
, H.ignoreOnWindows "transaction" Cardano.Testnet.Test.Cli.Babbage.Transaction.hprop_transaction
]
-- TODO: Conway - Re-enable when create-staked is working in conway again
--, testGroup "Conway"
--, T.testGroup "Conway"
-- [ H.ignoreOnWindows "stake-snapshot" Cardano.Testnet.Test.Cli.Conway.StakeSnapshot.hprop_stakeSnapshot
-- ]
-- Ignored on Windows due to <stdout>: commitBuffer: invalid argument (invalid character)
Expand All @@ -75,25 +74,13 @@ tests = do
, H.ignoreOnWindows "CliQueries" Cardano.Testnet.Test.Cli.Queries.hprop_cli_queries
]
]
, testGroup "SubmitApi"
[ testGroup "Babbage"
, T.testGroup "SubmitApi"
[ T.testGroup "Babbage"
[ H.ignoreOnWindows "transaction" Cardano.Testnet.Test.SubmitApi.Babbage.Transaction.hprop_transaction
]
]
]

shouldRunInParallel :: IO Bool
shouldRunInParallel = (== Just "1") <$> E.lookupEnv "PARALLEL_TESTNETS"

-- FIXME Right now when running tests concurrently it makes them flaky
runTestGroup
:: Bool -- ^ True to run in parallel
-> T.TestName
-> [TestTree]
-> TestTree
runTestGroup True name = T.testGroup name
runTestGroup False name = T.sequentialTestGroup name T.AllFinish

ingredients :: [T.Ingredient]
ingredients = T.defaultIngredients

Expand Down

0 comments on commit 350a5e1

Please sign in to comment.