Skip to content

Commit

Permalink
Improve readability of leadership check
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jan 5, 2023
1 parent bd2d757 commit 3141ca1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
11 changes: 6 additions & 5 deletions cardano-testnet/test/Test/Cli/Alonzo/LeadershipSchedule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,13 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"

leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime

H.byDeadlineM 10 leadershipDeadline "Wait for a leadership at least as new as the highest one we expect" $ do
leaderSlots <- H.getRelevantLeaderSlots (TR.nodeStdout $ TR.poolRuntime poolNode1) (minimum expectedLeadershipSlotNumbers)
maxActualSlot <- H.noteShow $ maximum leaderSlots
-- We need enough time to pass such that the expected leadership slots generated by the
-- leadership-schedule command have actually occurred.
leaderSlots <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
someLeaderSlots <- H.getRelevantLeaderSlots (TR.nodeStdout $ TR.poolRuntime poolNode1) (minimum expectedLeadershipSlotNumbers)
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
H.assert $ maxActualSlot >= maxSlotExpected

leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
pure someLeaderSlots

-- It's possible for some slots to not be assigned in TPraos when BFT nodes are running.
-- TODO Remove BFT nodes from testnet and assert the schedule is equal to actual slots
Expand Down
27 changes: 14 additions & 13 deletions cardano-testnet/test/Test/Cli/Babbage/LeadershipSchedule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"

leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime

-- Retrieve actual slots
H.byDeadlineM 10 leadershipDeadline "Wait for a leadership at least as new as the highest one we expect" $ do
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
if L.null leaderSlots
-- We need enough time to pass such that the expected leadership slots generated by the
-- leadership-schedule command have actually occurred.
leaderSlots <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
someLeaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
if L.null someLeaderSlots
then H.failure
else do
maxActualSlot <- H.noteShow $ maximum leaderSlots
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
H.assert $ maxActualSlot >= maxSlotExpected

leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
pure someLeaderSlots

H.noteShow_ expectedLeadershipSlotNumbers
H.noteShow_ leaderSlots
Expand Down Expand Up @@ -179,15 +179,16 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"

leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime

H.byDeadlineM 10 leadershipDeadline "Wait for a leadership at least as new as the highest one we expect" $ do
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
if L.null leaderSlots
-- We need enough time to pass such that the expected leadership slots generated by the
-- leadership-schedule command have actually occurred.
leaderSlots <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
someLeaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
if L.null someLeaderSlots
then H.failure
else do
maxActualSlot <- H.noteShow $ maximum leaderSlots
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
H.assert $ maxActualSlot >= maxSlotExpected

leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
pure someLeaderSlots

H.noteShow_ expectedLeadershipSlotNumbers
H.noteShow_ leaderSlots
Expand Down

0 comments on commit 3141ca1

Please sign in to comment.