Skip to content

Commit 479df51

Browse files
authored
Remove flaky calls to by byDeadlineM in cardano-testnet (IntersectMBO#5707)
* Use waitUntilEpoch in hprop_leadershipSchedule * Remove byDeadlineM when querying the leadership schedule in hprop_leadershipSchedule * Replace with byDeadlineM with waitUntilEpoch in hprop_stakeSnapshot
1 parent e9600ef commit 479df51

File tree

3 files changed

+50
-82
lines changed

3 files changed

+50
-82
lines changed

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/LeadershipSchedule.hs

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module Cardano.Testnet.Test.Cli.Babbage.LeadershipSchedule
1515
) where
1616

1717
import Cardano.Api
18+
import qualified Cardano.Api as Api
1819

19-
import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (..))
2020
import Cardano.Node.Configuration.Topology
2121
import Cardano.Testnet
2222

@@ -32,7 +32,6 @@ import qualified Data.Map.Strict as Map
3232
import Data.Text (Text)
3333
import qualified Data.Text as Text
3434
import qualified Data.Time.Clock as DTC
35-
import GHC.Stack (callStack)
3635
import qualified GHC.Stack as GHC
3736
import System.FilePath ((</>))
3837
import qualified System.Info as SYS
@@ -49,6 +48,7 @@ import Testnet.Runtime
4948
import Hedgehog (Property, (===))
5049
import qualified Hedgehog as H
5150
import Hedgehog.Extras (threadDelay)
51+
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
5252
import qualified Hedgehog.Extras.Test.Base as H
5353
import qualified Hedgehog.Extras.Test.File as H
5454

@@ -193,6 +193,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
193193
, "--tx-file", delegRegTestDelegatorTxFp
194194
]
195195

196+
-- TODO: Can be removed if checkStakeKeyRegistered uses foldEpochState
196197
threadDelay 15_000000
197198

198199
-------------------------------------------------------------------
@@ -253,74 +254,56 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
253254
testPoolStdOutFp <- case eRuntime of
254255
Left e -> H.failMessage GHC.callStack $ "Failed to start node: " <> show e
255256
Right runtime -> return $ nodeStdout runtime
256-
threadDelay 5_000000
257257

258+
-- Wait for 2 epochs to pass
259+
void $ waitUntilEpoch (Api.File configurationFile)
260+
(Api.File $ IO.sprocketSystemName node1sprocket) (EpochNo 3)
258261

259-
tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
262+
currentLeaderShipScheduleFile <- H.noteTempFile work "current-schedule.log"
260263

261-
H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
262-
void $ execCli' execConfig
263-
[ "query", "tip"
264-
, "--out-file", work </> "current-tip.json"
265-
]
266-
267-
tipJson <- H.leftFailM . H.readJsonFile $ work </> "current-tip.json"
268-
tip <- H.noteShowM $ H.jsonErrorFail $ J.fromJSON @QueryTipLocalStateOutput tipJson
269-
270-
currEpoch <- case mEpoch tip of
271-
Nothing -> H.failMessage callStack "cardano-cli query tip returned Nothing for EpochNo"
272-
Just currEpoch -> return currEpoch
273-
274-
H.note_ $ "Current Epoch: " <> show currEpoch
275-
H.assert $ currEpoch > 2
276-
277-
id do
278-
currentLeaderShipScheduleFile <- H.noteTempFile work "current-schedule.log"
279-
280-
leadershipScheduleDeadline <- H.noteShowM $ DTC.addUTCTime 180 <$> H.noteShowIO DTC.getCurrentTime
281-
282-
H.byDeadlineM 5 leadershipScheduleDeadline "Failed to query for leadership schedule" $ do
283-
void $ execCli' execConfig
284-
[ "query", "leadership-schedule"
285-
, "--genesis", shelleyGenesisFile tr
286-
, "--stake-pool-id", stakePoolIdNewSpo
287-
, "--vrf-signing-key-file", vrfSkey
288-
, "--out-file", currentLeaderShipScheduleFile
289-
, "--current"
290-
]
264+
void $ execCli' execConfig
265+
[ "query", "leadership-schedule"
266+
, "--genesis", shelleyGenesisFile tr
267+
, "--stake-pool-id", stakePoolIdNewSpo
268+
, "--vrf-signing-key-file", vrfSkey
269+
, "--out-file", currentLeaderShipScheduleFile
270+
, "--current"
271+
]
291272

292-
currentScheduleJson <- H.leftFailM $ H.readJsonFile currentLeaderShipScheduleFile
273+
currentScheduleJson <- H.leftFailM $ H.readJsonFile currentLeaderShipScheduleFile
293274

294-
expectedLeadershipSlotNumbers <- H.noteShowM $ fmap (fmap slotNumber) $ H.leftFail $ J.parseEither (J.parseJSON @[LeadershipSlot]) currentScheduleJson
275+
expectedLeadershipSlotNumbers <- H.noteShowM $ fmap (fmap slotNumber) $ H.leftFail $ J.parseEither (J.parseJSON @[LeadershipSlot]) currentScheduleJson
295276

296-
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
277+
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
297278

298-
H.assert $ not (L.null expectedLeadershipSlotNumbers)
279+
H.assert $ not (L.null expectedLeadershipSlotNumbers)
299280

300-
leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime
281+
leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime
301282

302283
-- We need enough time to pass such that the expected leadership slots generated by the
303284
-- leadership-schedule command have actually occurred.
304-
(leaderSlots, notLeaderSlots) <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
305-
(someLeaderSlots, someNotLeaderSlots) <- getRelevantSlots testPoolStdOutFp (minimum expectedLeadershipSlotNumbers)
306-
if L.null someLeaderSlots
307-
then H.failure
308-
else do
309-
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
310-
H.assert $ maxActualSlot >= maxSlotExpected
311-
pure (someLeaderSlots, someNotLeaderSlots)
312-
313-
H.noteShow_ expectedLeadershipSlotNumbers
314-
H.noteShow_ leaderSlots
315-
H.noteShow_ notLeaderSlots
285+
-- TODO: We can further improve this if parameterize foldEpochState's callback on
286+
-- the current slot and current block number.
287+
(leaderSlots, notLeaderSlots) <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
288+
(someLeaderSlots, someNotLeaderSlots) <- getRelevantSlots testPoolStdOutFp (minimum expectedLeadershipSlotNumbers)
289+
if L.null someLeaderSlots
290+
then H.failure
291+
else do
292+
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
293+
H.assert $ maxActualSlot >= maxSlotExpected
294+
pure (someLeaderSlots, someNotLeaderSlots)
295+
296+
H.noteShow_ expectedLeadershipSlotNumbers
297+
H.noteShow_ leaderSlots
298+
H.noteShow_ notLeaderSlots
316299

317300
-- Double check that we've seen all slots
318-
H.noteShow_ ("Slots not seen as TraceNodeIsLeader nor TraceNodeNotLeader" :: Text)
319-
([minimum expectedLeadershipSlotNumbers .. maxSlotExpected] \\ leaderSlots) \\ notLeaderSlots === []
301+
H.noteShow_ ("Slots not seen as TraceNodeIsLeader nor TraceNodeNotLeader" :: Text)
302+
([minimum expectedLeadershipSlotNumbers .. maxSlotExpected] \\ leaderSlots) \\ notLeaderSlots === []
320303

321304
-- As there are no BFT nodes, the next leadership schedule should match slots assigned exactly
322-
H.noteShow_ (expectedLeadershipSlotNumbers \\ leaderSlots)
323-
H.assert $ L.null (expectedLeadershipSlotNumbers \\ leaderSlots)
305+
H.noteShow_ (expectedLeadershipSlotNumbers \\ leaderSlots)
306+
H.assert $ L.null (expectedLeadershipSlotNumbers \\ leaderSlots)
324307
-- TODO: Re-enable --next leadership schedule test
325308
{-
326309

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Babbage/StakeSnapshot.hs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ module Cardano.Testnet.Test.Cli.Babbage.StakeSnapshot
1010
) where
1111

1212
import Cardano.Api
13+
import qualified Cardano.Api as Api
1314

14-
import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (..))
1515
import Cardano.Testnet
1616

1717
import Prelude
1818

19+
import Control.Monad
1920
import qualified Data.Aeson as Aeson
2021
import qualified Data.Aeson.KeyMap as KM
21-
import qualified Data.Time.Clock as DTC
22-
import GHC.Stack (callStack)
2322
import qualified System.Info as SYS
2423

2524
import Testnet.Process.Cli (execCliStdoutToJson)
@@ -29,6 +28,7 @@ import Testnet.Runtime
2928

3029
import Hedgehog (Property, (===))
3130
import qualified Hedgehog as H
31+
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
3232
import qualified Hedgehog.Extras.Test.Base as H
3333

3434
hprop_stakeSnapshot :: Property
@@ -49,22 +49,15 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "babbage-stake-snapshot" $ \
4949
TestnetRuntime
5050
{ testnetMagic
5151
, poolNodes
52+
, configurationFile
5253
} <- cardanoTestnetDefault options conf
5354

5455
poolNode1 <- H.headM poolNodes
5556
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
5657
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
57-
tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
5858

59-
H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
60-
tip <- execCliStdoutToJson execConfig [ "query", "tip" ]
61-
62-
currEpoch <- case mEpoch tip of
63-
Nothing -> H.failMessage callStack "cardano-cli query tip returned Nothing for EpochNo"
64-
Just currEpoch -> return currEpoch
65-
66-
H.note_ $ "Current Epoch: " <> show currEpoch
67-
H.assert $ currEpoch > 2
59+
void $ waitUntilEpoch (Api.File configurationFile)
60+
(Api.File $ IO.sprocketSystemName poolSprocket1) (EpochNo 3)
6861

6962
json <- execCliStdoutToJson execConfig [ "query", "stake-snapshot", "--all-stake-pools" ]
7063

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/Cli/Conway/StakeSnapshot.hs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ module Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
99
( hprop_stakeSnapshot
1010
) where
1111

12-
import Cardano.Api
12+
import Cardano.Api as Api
1313

14-
import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (..))
1514
import Cardano.Testnet
1615

1716
import Prelude
1817

18+
import Control.Monad
1919
import qualified Data.Aeson as Aeson
2020
import qualified Data.Aeson.KeyMap as KM
21-
import qualified Data.Time.Clock as DTC
22-
import GHC.Stack (callStack)
2321
import qualified System.Info as SYS
2422

2523
import Testnet.Process.Cli (execCliStdoutToJson)
@@ -29,6 +27,7 @@ import Testnet.Runtime
2927

3028
import Hedgehog (Property, (===))
3129
import qualified Hedgehog as H
30+
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
3231
import qualified Hedgehog.Extras.Test.Base as H
3332

3433
hprop_stakeSnapshot :: Property
@@ -48,23 +47,16 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "conway-stake-snapshot" $ \t
4847
TestnetRuntime
4948
{ testnetMagic
5049
, poolNodes
50+
, configurationFile
5151
} <- cardanoTestnetDefault options conf
5252

5353
poolNode1 <- H.headM poolNodes
5454
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
5555
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
5656

57-
tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
57+
void $ waitUntilEpoch (Api.File configurationFile)
58+
(Api.File $ IO.sprocketSystemName poolSprocket1) (EpochNo 3)
5859

59-
H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
60-
tip <- execCliStdoutToJson execConfig [ "query", "tip" ]
61-
62-
currEpoch <- case mEpoch tip of
63-
Nothing -> H.failMessage callStack "cardano-cli query tip returned Nothing for EpochNo"
64-
Just currEpoch -> return currEpoch
65-
66-
H.note_ $ "Current Epoch: " <> show currEpoch
67-
H.assert $ currEpoch > 2
6860

6961
json <- execCliStdoutToJson execConfig [ "query", "stake-snapshot", "--all-stake-pools" ]
7062

0 commit comments

Comments
 (0)