Skip to content

Commit df58013

Browse files
committed
Remove assertByDeadlineMCustom function
1 parent fdc57f5 commit df58013

File tree

4 files changed

+20
-35
lines changed

4 files changed

+20
-35
lines changed

Diff for: cardano-testnet/src/Testnet/Babbage.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ babbageTestnet testnetOptions H.Conf {..} = do
335335
return $ PoolNode runtime key
336336

337337
now <- H.noteShowIO DTC.getCurrentTime
338-
deadline <- H.noteShow $ DTC.addUTCTime 110 now
338+
deadline <- H.noteShow $ DTC.addUTCTime 90 now
339339

340340
forM_ spoNodes $ \node -> do
341341
nodeStdoutFile <- H.noteTempFile logDir $ node <> ".stdout.log"

Diff for: cardano-testnet/src/Util/Process.hs

-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module Util.Process
22
( assertByDeadlineIOCustom
3-
, assertByDeadlineMCustom
43
, bashPath
54
, execCli
65
, execCli_
@@ -132,26 +131,10 @@ assertByDeadlineIOCustom str deadline f = GHC.withFrozenCallStack $ do
132131
success <- liftIO f
133132
unless success $ do
134133
currentTime <- liftIO DTC.getCurrentTime
135-
note_ $ "Current time: " <> show currentTime
136134
if currentTime < deadline
137135
then do
138136
liftIO $ IO.threadDelay 1000000
139137
assertByDeadlineIOCustom str deadline f
140138
else do
141139
H.annotateShow currentTime
142140
failMessage GHC.callStack $ "Condition not met by deadline: " <> str
143-
144-
assertByDeadlineMCustom
145-
:: (MonadTest m, MonadIO m, HasCallStack)
146-
=> String -> UTCTime -> m Bool -> m ()
147-
assertByDeadlineMCustom str deadline f = GHC.withFrozenCallStack $ do
148-
success <- f
149-
unless success $ do
150-
currentTime <- liftIO DTC.getCurrentTime
151-
if currentTime < deadline
152-
then do
153-
liftIO $ IO.threadDelay 1000000
154-
assertByDeadlineMCustom str deadline f
155-
else do
156-
H.annotateShow currentTime
157-
failMessage GHC.callStack $ "Condition not met by deadline: " <> str

Diff for: cardano-testnet/test/Test/Cli/Alonzo/LeadershipSchedule.hs

+9-8
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ import qualified System.Directory as IO
4242
import System.Environment (getEnvironment)
4343
import System.FilePath ((</>))
4444
import qualified System.Info as SYS
45-
import Testnet ( TestnetOptions (CardanoOnlyTestnetOptions), testnet)
45+
import Testnet (TestnetOptions (CardanoOnlyTestnetOptions), testnet)
4646
import Testnet.Cardano as TC (CardanoTestnetOptions (..), defaultTestnetOptions)
4747
import qualified Testnet.Conf as H
4848
import Testnet.Utils (waitUntilEpoch)
4949
import qualified Util.Assert as H
5050
import qualified Util.Base as H
5151
import qualified Util.Process as H
52-
import Util.Runtime (LeadershipSlot (..))
5352
import qualified Util.Runtime as TR
53+
import Util.Runtime (LeadershipSlot (..))
5454

5555
hprop_leadershipSchedule :: Property
5656
hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo" $ \tempAbsBasePath' -> do
@@ -454,8 +454,7 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"
454454
now <- H.noteShowIO DTC.getCurrentTime
455455
deadline <- H.noteShow $ DTC.addUTCTime 90 now
456456

457-
H.assertByDeadlineMCustom "stdout does not contain \"until genesis start time\"" deadline $ do
458-
H.threadDelay 1000000
457+
H.byDeadlineM 10 deadline $ do
459458
void $ H.execCli' execConfig
460459
[ "query", "tip"
461460
, "--testnet-magic", show @Int testnetMagic
@@ -470,7 +469,7 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"
470469
Just currEpoch3 -> return currEpoch3
471470

472471
H.note_ $ "Current Epoch: " <> show currEpoch3
473-
return (currEpoch3 > currEpoch2 + 1)
472+
H.assert $ currEpoch3 > currEpoch2 + 1
474473

475474
ledgerStateJson <- H.execCli' execConfig
476475
[ "query", "ledger-state"
@@ -499,15 +498,17 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"
499498

500499
expectedLeadershipSlotNumbers <- H.noteShowM $ fmap (fmap slotNumber) $ H.leftFail $ J.parseEither (J.parseJSON @[LeadershipSlot]) scheduleJson
501500

501+
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
502+
502503
H.assert $ not (L.null expectedLeadershipSlotNumbers)
503504

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

506-
H.assertByDeadlineMCustom "Leader schedule is correct" leadershipDeadline $ do
507+
-- Leader schedule is correct
508+
H.byDeadlineM 10 leadershipDeadline $ do
507509
leaderSlots <- H.getRelevantLeaderSlots (TR.nodeStdout $ TR.poolRuntime poolNode1) (minimum expectedLeadershipSlotNumbers)
508-
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
509510
maxActualSlot <- H.noteShow $ maximum leaderSlots
510-
return $ maxActualSlot >= maxSlotExpected
511+
H.assert $ maxActualSlot >= maxSlotExpected
511512

512513
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
513514

Diff for: cardano-testnet/test/Test/Cli/Babbage/LeadershipSchedule.hs

+10-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import qualified Data.Time.Clock as DTC
3333
import qualified Hedgehog as H
3434
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
3535
import qualified Hedgehog.Extras.Test.Base as H
36-
import qualified Hedgehog.Extras.Test.Concurrent as H
3736
import qualified Hedgehog.Extras.Test.File as H
3837
import qualified Hedgehog.Extras.Test.Process as H
3938
import qualified System.Directory as IO
@@ -90,7 +89,6 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"
9089

9190
-- stdout must contain \"until genesis start time\""
9291
H.byDeadlineM 10 tipDeadline $ do
93-
H.threadDelay 5000000
9492
void $ H.execCli' execConfig
9593
[ "query", "tip"
9694
, "--testnet-magic", show @Int testnetMagic
@@ -134,18 +132,20 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"
134132

135133
expectedLeadershipSlotNumbers <- H.noteShowM $ fmap (fmap slotNumber) $ H.leftFail $ J.parseEither (J.parseJSON @[LeadershipSlot]) scheduleJson
136134

135+
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
136+
137137
H.assert $ not (L.null expectedLeadershipSlotNumbers)
138138

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

141-
H.assertByDeadlineMCustom "Retrieve actual slots" leadershipDeadline $ do
141+
-- Retrieve actual slots
142+
H.byDeadlineM 10 leadershipDeadline $ do
142143
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
143-
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
144144
if L.null leaderSlots
145-
then return False
145+
then H.failure
146146
else do
147147
maxActualSlot <- H.noteShow $ maximum leaderSlots
148-
return $ maxActualSlot >= maxSlotExpected
148+
H.assert $ maxActualSlot >= maxSlotExpected
149149

150150
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
151151

@@ -180,13 +180,14 @@ hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo"
180180

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

183-
H.assertByDeadlineMCustom "Retrieve actual slots" leadershipDeadline $ do
183+
-- Retrieve actual slots
184+
H.byDeadlineM 10 leadershipDeadline $ do
184185
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
185186
if L.null leaderSlots
186-
then return False
187+
then H.failure
187188
else do
188189
maxActualSlot <- H.noteShow $ maximum leaderSlots
189-
return $ maxActualSlot >= maxSlotExpected
190+
H.assert $ maxActualSlot >= maxSlotExpected
190191

191192
leaderSlots <- H.getRelevantLeaderSlots (TR.poolNodeStdout poolNode1) (minimum expectedLeadershipSlotNumbers)
192193

0 commit comments

Comments
 (0)