Skip to content

Commit 568a7ac

Browse files
committed
Review changes
1 parent d7b60ca commit 568a7ac

File tree

8 files changed

+37
-33
lines changed

8 files changed

+37
-33
lines changed

cardano-testnet/src/Testnet/Components/Query.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import Cardano.Api as Api hiding (txId)
4747
import Cardano.Api.Ledger (Credential, DRepState, EpochInterval (..), KeyRole (DRepRole))
4848
import qualified Cardano.Api.Ledger as L
4949
import qualified Cardano.Api.UTxO as Utxo
50-
50+
import Testnet.Runtime
5151
import Cardano.Ledger.Api (ConwayGovState)
5252
import qualified Cardano.Ledger.Api as L
5353
import qualified Cardano.Ledger.Conway.Governance as L
@@ -253,13 +253,12 @@ getEpochStateView
253253
:: HasCallStack
254254
=> MonadResource m
255255
=> MonadTest m
256-
=> MonadCatch m
257256
=> NodeConfigFile In -- ^ node Yaml configuration file path
258257
-> SocketPath -- ^ node socket path
259258
-> m EpochStateView
260259
getEpochStateView nodeConfigFile socketPath = withFrozenCallStack $ do
261260
epochStateView <- H.evalIO $ newIORef Nothing
262-
H.asyncRegister_ . runExceptT . foldEpochState nodeConfigFile socketPath QuickValidation (EpochNo maxBound) Nothing
261+
void . asyncRegister_ . runExceptT . foldEpochState nodeConfigFile socketPath QuickValidation (EpochNo maxBound) Nothing
263262
$ \epochState slotNumber blockNumber -> do
264263
liftIO . writeIORef epochStateView $ Just (epochState, slotNumber, blockNumber)
265264
pure ConditionNotMet

cardano-testnet/src/Testnet/Orphans.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Testnet.Orphans () where
44

5-
import RIO (RIO(..), liftIO)
5+
import RIO (RIO(..), throwString)
66

77
instance MonadFail (RIO env) where
8-
fail = liftIO . fail
8+
fail = throwString

cardano-testnet/src/Testnet/Process/RunIO.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ defaultExecConfig = ExecConfig
4444

4545

4646
mkExecConfig :: ()
47+
=> HasCallStack
4748
=> MonadIO m
4849
=> FilePath
4950
-> IO.Sprocket
@@ -65,7 +66,8 @@ mkExecConfig tempBaseAbsPath sprocket networkId = do
6566

6667

6768
execCli'
68-
:: MonadIO m
69+
:: HasCallStack
70+
=> MonadIO m
6971
=> ExecConfig
7072
-> [String]
7173
-> m String
@@ -94,14 +96,16 @@ execCli = GHC.withFrozenCallStack $ execFlex "cardano-cli" "CARDANO_CLI"
9496
-- When running outside a nix environment, the `pkgBin` describes the name of the binary
9597
-- to launch via cabal exec.
9698
execFlex
97-
:: String
99+
:: HasCallStack
100+
=> String
98101
-> String
99102
-> [String]
100103
-> RIO env String
101104
execFlex = execFlex' defaultExecConfig
102105

103106
execFlex'
104107
:: MonadIO m
108+
=> HasCallStack
105109
=> ExecConfig
106110
-> String
107111
-> String
@@ -278,7 +282,7 @@ procFlex
278282
-- ^ Captured stdout
279283
procFlex = procFlex' defaultExecConfig
280284

281-
285+
-- This will also catch async exceptions as well.
282286
liftIOAnnotated :: (HasCallStack, MonadIO m) => IO a -> m a
283287
liftIOAnnotated action = GHC.withFrozenCallStack $
284288
liftIO $ action `catch` (\(e :: SomeException) -> throwM $ exceptionWithCallStack e)

cardano-testnet/src/Testnet/Runtime.hs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ startNode tp node ipv4 port _testnetMagic nodeCmd = GHC.withFrozenCallStack $ do
156156

157157
isClosed <- liftIOAnnotated $ Ping.waitForPortClosed 30 0.1 port
158158
unless isClosed $
159-
throwString $ "Port is still in use after 30 seconds before starting node: " <> show port
159+
throwString $ "Port is still in use after 30 seconds before starting node: " <> show port
160160

161161
(Just stdIn, _, _, hProcess, _)
162162
<- firstExceptT ProcessRelatedFailure $ initiateProcess
@@ -278,7 +278,6 @@ createSubdirectoryIfMissingNew parent subdirectory = GHC.withFrozenCallStack $ d
278278
-- Idempotent.
279279
startLedgerNewEpochStateLogging
280280
:: HasCallStack
281-
=> MonadCatch m
282281
=> MonadResource m
283282
=> TestnetRuntime
284283
-> FilePath -- ^ tmp workspace directory
@@ -294,23 +293,24 @@ startLedgerNewEpochStateLogging testnetRuntime tmpWorkspace = withFrozenCallStac
294293
False -> do
295294
throwString $ "Log directory does not exist: " <> logDir <> " - cannot start logging epoch states"
296295

297-
liftIOAnnotated $ IO.doesFileExist logFile >>= \case
296+
liftIOAnnotated (IO.doesFileExist logFile) >>= \case
298297
True -> return ()
299-
False -> liftIO $ appendFile logFile ""
300-
301-
let socketPath = case uncons (testnetSprockets testnetRuntime) of
302-
Just (sprocket, _) -> H.sprocketSystemName sprocket
303-
Nothing -> throwString "No testnet sprocket available"
304-
305-
let act = runExceptT $
306-
foldEpochState
307-
(configurationFile testnetRuntime)
308-
(Api.File socketPath)
309-
Api.QuickValidation
310-
(EpochNo maxBound)
311-
Nothing
312-
(handler logFile diffFile)
313-
void $ asyncRegister_ act
298+
False -> do
299+
liftIOAnnotated $ appendFile logFile ""
300+
301+
let socketPath = case uncons (testnetSprockets testnetRuntime) of
302+
Just (sprocket, _) -> H.sprocketSystemName sprocket
303+
Nothing -> throwString "No testnet sprocket available"
304+
305+
void $ asyncRegister_ . runExceptT $
306+
foldEpochState
307+
(configurationFile testnetRuntime)
308+
(Api.File socketPath)
309+
Api.QuickValidation
310+
(EpochNo maxBound)
311+
Nothing
312+
(handler logFile diffFile)
313+
314314
where
315315
handler :: FilePath -- ^ log file
316316
-> FilePath -- ^ diff file

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import Data.Time (diffUTCTime)
5757
import Data.Time.Clock (NominalDiffTime)
5858
import qualified Data.Time.Clock as DTC
5959
import GHC.Stack
60+
import Hedgehog ( evalIO )
6061
import qualified System.Directory as IO
6162
import System.FilePath ((</>))
6263

@@ -93,7 +94,7 @@ testMinimumConfigurationRequirements options = withFrozenCallStack $ do
9394
liftToIntegration :: RIO ResourceMap a -> H.Integration a
9495
liftToIntegration r = do
9596
rMap <- lift $ lift getInternalState
96-
liftIOAnnotated $ runRIO rMap r
97+
evalIO $ runRIO rMap r
9798

9899
createTestnetEnv :: ()
99100
=> HasCallStack

cardano-testnet/src/Testnet/Start/Types.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Cardano.Ledger.Conway.Genesis (ConwayGenesis)
5252
import Prelude
5353

5454
import Control.Exception (throw)
55+
import Control.Monad (unless)
5556
import qualified Data.Aeson as Aeson
5657
import Data.Aeson.Types (parseFail)
5758
import Data.Char (toLower)
@@ -288,7 +289,6 @@ data Conf = Conf
288289
, updateTimestamps :: UpdateTimestamps
289290
} deriving (Eq, Show)
290291

291-
-- Logs the argument in the test.
292292
mkConf :: (HasCallStack, MonadTest m) => FilePath -> m Conf
293293
mkConf tempAbsPath' = withFrozenCallStack $ do
294294
H.note_ tempAbsPath'
@@ -309,12 +309,9 @@ mkConfigAbs userOutputDir = do
309309
absUserOutputDir <- makeAbsolute userOutputDir
310310
dirExists <- doesDirectoryExist absUserOutputDir
311311
let conf = mkConfig absUserOutputDir
312-
if dirExists then
313-
-- Happens when the environment has previously been created by the user
314-
return conf
315-
else do
312+
unless dirExists $
316313
createDirectory absUserOutputDir
317-
return conf
314+
pure conf
318315

319316
-- | @anyEraToString (AnyCardanoEra ByronEra)@ returns @"byron"@
320317
anyEraToString :: AnyCardanoEra -> String

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SanityCheck.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ hprop_asyncRegister_sanity_check =
105105
(internalState,tId) <- runResourceT $ do
106106
s <- getInternalState
107107
(_,asyncA) <- asyncRegister_ (threadDelay 10_000_000)
108+
threadDelay 10_000_000
108109
let tId = asyncThreadId asyncA
109110
return (s,tId)
110111
afterForkedThread <- getCurrentTime

cardano-testnet/test/cardano-testnet-test/cardano-testnet-test.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import qualified Cardano.Testnet.Test.Cli.Plutus.Scripts
1212
import qualified Cardano.Testnet.Test.Cli.Query
1313
import qualified Cardano.Testnet.Test.Cli.QuerySlotNumber
1414
import qualified Cardano.Testnet.Test.Cli.StakeSnapshot
15+
import qualified Cardano.Testnet.Test.SanityCheck
1516
import qualified Cardano.Testnet.Test.Cli.Transaction
1617
import qualified Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
1718
import qualified Cardano.Testnet.Test.DumpConfig
@@ -56,6 +57,7 @@ tests = do
5657
[ T.testGroup "Spec"
5758
[ T.testGroup "Ledger Events"
5859
[ ignoreOnWindows "Sanity Check" LedgerEvents.hprop_ledger_events_sanity_check
60+
, ignoreOnWindows "Async Register" Cardano.Testnet.Test.SanityCheck.hprop_asyncRegister_sanity_check
5961
-- FIXME this tests gets stuck - investigate why
6062
-- , ignoreOnWindows "Treasury Growth" Gov.prop_check_if_treasury_is_growing
6163
-- TODO: Replace foldBlocks with checkConditionResult

0 commit comments

Comments
 (0)