Skip to content

Commit ca2f559

Browse files
authored
Merge pull request #1619 from IntersectMBO/1618-test-configfile-opts
Test to allow custom Config values
2 parents dd01f51 + 804fe89 commit ca2f559

File tree

16 files changed

+187
-102
lines changed

16 files changed

+187
-102
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ mkConfig staticDir mutableDir cmdLineArgs config = do
229229
pure $ Config (Consensus.pInfoConfig pInfoDbSync) pInfoDbSync pInfoForger forging' syncPars
230230

231231
mkSyncNodeConfig :: FilePath -> IO SyncNodeConfig
232-
mkSyncNodeConfig staticDir =
233-
readSyncNodeConfig $ ConfigFile (staticDir </> "test-db-sync-config.json")
232+
mkSyncNodeConfig configFilePath =
233+
readSyncNodeConfig $ ConfigFile (mkConfigDir configFilePath </> "test-db-sync-config.json")
234234

235235
mkShelleyCredentials :: FilePath -> IO [ShelleyLeaderCredentials StandardCrypto]
236236
mkShelleyCredentials bulkFile = do
@@ -325,7 +325,16 @@ withFullConfig ::
325325
IOManager ->
326326
[(Text, Text)] ->
327327
IO a
328-
withFullConfig = withFullConfig' (WithConfigArgs True False False) initCommandLineArgs
328+
withFullConfig =
329+
withFullConfig'
330+
( WithConfigArgs
331+
{ hasFingerprint = True
332+
, shouldLog = False
333+
, shouldDropDB = False
334+
}
335+
)
336+
initCommandLineArgs
337+
Nothing
329338

330339
-- this function needs to be used where the schema needs to be rebuilt
331340
withFullConfigAndDropDB ::
@@ -337,19 +346,41 @@ withFullConfigAndDropDB ::
337346
IOManager ->
338347
[(Text, Text)] ->
339348
IO a
340-
withFullConfigAndDropDB = withFullConfig' (WithConfigArgs True False True) initCommandLineArgs
349+
withFullConfigAndDropDB =
350+
withFullConfig'
351+
( WithConfigArgs
352+
{ hasFingerprint = True
353+
, shouldLog = False
354+
, shouldDropDB = True
355+
}
356+
)
357+
initCommandLineArgs
358+
Nothing
341359

342360
withFullConfigAndLogs ::
361+
-- | config filepath
343362
FilePath ->
363+
-- | test label
344364
FilePath ->
345365
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a) ->
346366
IOManager ->
347367
[(Text, Text)] ->
348368
IO a
349-
withFullConfigAndLogs = withFullConfig' (WithConfigArgs True True False) initCommandLineArgs
369+
withFullConfigAndLogs =
370+
withFullConfig'
371+
( WithConfigArgs
372+
{ hasFingerprint = True
373+
, shouldLog = True
374+
, shouldDropDB = False
375+
}
376+
)
377+
initCommandLineArgs
378+
Nothing
350379

351380
withCustomConfig ::
352381
CommandLineArgs ->
382+
-- | custom SyncNodeConfig
383+
Maybe SyncNodeConfig ->
353384
-- | config filepath
354385
FilePath ->
355386
-- | test label
@@ -358,10 +389,19 @@ withCustomConfig ::
358389
IOManager ->
359390
[(Text, Text)] ->
360391
IO a
361-
withCustomConfig = withFullConfig' (WithConfigArgs True False False)
392+
withCustomConfig =
393+
withFullConfig'
394+
( WithConfigArgs
395+
{ hasFingerprint = True
396+
, shouldLog = False
397+
, shouldDropDB = False
398+
}
399+
)
362400

363401
withCustomConfigAndDropDB ::
364402
CommandLineArgs ->
403+
-- | custom SyncNodeConfig
404+
Maybe SyncNodeConfig ->
365405
-- | config filepath
366406
FilePath ->
367407
-- | test label
@@ -370,11 +410,20 @@ withCustomConfigAndDropDB ::
370410
IOManager ->
371411
[(Text, Text)] ->
372412
IO a
373-
withCustomConfigAndDropDB = withFullConfig' (WithConfigArgs True False True)
413+
withCustomConfigAndDropDB =
414+
withFullConfig'
415+
( WithConfigArgs
416+
{ hasFingerprint = True
417+
, shouldLog = False
418+
, shouldDropDB = True
419+
}
420+
)
374421

375422
-- This is a usefull function to be able to see logs from DBSync when writing/debuging tests
376423
withCustomConfigAndLogs ::
377424
CommandLineArgs ->
425+
-- | custom SyncNodeConfig
426+
Maybe SyncNodeConfig ->
378427
-- | config filepath
379428
FilePath ->
380429
-- | test label
@@ -383,11 +432,20 @@ withCustomConfigAndLogs ::
383432
IOManager ->
384433
[(Text, Text)] ->
385434
IO a
386-
withCustomConfigAndLogs = withFullConfig' (WithConfigArgs True True False)
435+
withCustomConfigAndLogs =
436+
withFullConfig'
437+
( WithConfigArgs
438+
{ hasFingerprint = True
439+
, shouldLog = True
440+
, shouldDropDB = False
441+
}
442+
)
387443

388444
withFullConfig' ::
389445
WithConfigArgs ->
390446
CommandLineArgs ->
447+
-- | custom SyncNodeConfig
448+
Maybe SyncNodeConfig ->
391449
-- | config filepath
392450
FilePath ->
393451
-- | test label
@@ -396,17 +454,23 @@ withFullConfig' ::
396454
IOManager ->
397455
[(Text, Text)] ->
398456
IO a
399-
withFullConfig' WithConfigArgs {..} cmdLineArgs configFilePath testLabelFilePath action iom migr = do
457+
withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath testLabelFilePath action iom migr = do
400458
recreateDir mutableDir
401-
cfg <- mkConfig configDir mutableDir cmdLineArgs =<< mkSyncNodeConfig configDir
459+
-- check if custom syncNodeConfigs have been passed or not
460+
syncNodeConfig <-
461+
case mSyncNodeConfig of
462+
Just snc -> pure snc
463+
Nothing -> mkSyncNodeConfig configFilePath
464+
465+
cfg <- mkConfig (mkConfigDir configFilePath) mutableDir cmdLineArgs syncNodeConfig
402466
fingerFile <- if hasFingerprint then Just <$> prepareFingerprintFile testLabelFilePath else pure Nothing
403467
let dbsyncParams = syncNodeParams cfg
404468
trce <-
405469
if shouldLog
406-
then configureLogging dbsyncParams "db-sync-node"
470+
then configureLogging syncNodeConfig "db-sync-node"
407471
else pure nullTracer
408472
-- runDbSync is partially applied so we can pass in syncNodeParams at call site / within tests
409-
let partialDbSyncRun params = runDbSync emptyMetricsSetters migr iom trce params True
473+
let partialDbSyncRun params = runDbSync emptyMetricsSetters migr iom trce params syncNodeConfig True
410474
initSt = Consensus.pInfoInitLedger $ protocolInfo cfg
411475

412476
withInterpreter (protocolInfoForging cfg) (protocolInfoForger cfg) nullTracer fingerFile $ \interpreter -> do
@@ -429,7 +493,6 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs configFilePath testLabelFilePath
429493
else void . hSilence [stderr] $ Db.truncateTables pgPass tableNames
430494
action interpreter mockServer dbSyncEnv
431495
where
432-
configDir = mkConfigDir configFilePath
433496
mutableDir = mkMutableDir testLabelFilePath
434497

435498
prepareFingerprintFile :: FilePath -> IO FilePath

cardano-chain-gen/test/Test/Cardano/Db/Mock/Property/Property.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,4 @@ prop_empty_blocks iom knownMigrations = withMaxSuccess 20 $ noShrinking $ forAll
274274
prettyCommands smSymbolic hist (checkCommandNames cmds (res === Ok))
275275
where
276276
smSymbolic = sm (error "inter") (error "mockServer") (error "dbSync")
277-
runAction action = withFullConfig' (WithConfigArgs False False False) initCommandLineArgs "config" "qsm" action iom knownMigrations
277+
runAction action = withFullConfig' (WithConfigArgs False False False) initCommandLineArgs Nothing "config" "qsm" action iom knownMigrations

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/CommandLineArg/ConfigFile.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Test.Tasty.HUnit (Assertion)
1212
-- this test fails as incorrect configuration file given
1313
checkConfigFileArg :: IOManager -> [(Text, Text)] -> Assertion
1414
checkConfigFileArg =
15-
withCustomConfig commandLineConfigArgs babbageConfigDir testLabel $ \_ _ dbSyncEnv -> do
15+
withCustomConfig commandLineConfigArgs Nothing babbageConfigDir testLabel $ \_ _ dbSyncEnv -> do
1616
-- poll dbSync to see if it's running, which it shouldn't
1717
checkStillRuns dbSyncEnv
1818
where

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/CommandLineArg/EpochDisabled.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mkCommandLineArgs epochDisabled = initCommandLineArgs {claEpochDisabled = epochD
2121
-- this test fails as incorrect configuration file given
2222
checkEpochDisabledArg :: IOManager -> [(Text, Text)] -> Assertion
2323
checkEpochDisabledArg =
24-
withCustomConfigAndDropDB (mkCommandLineArgs True) babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
24+
withCustomConfigAndDropDB (mkCommandLineArgs True) Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
2525
startDBSync dbSyncEnv
2626
b1 <- forgeAndSubmitBlocks interpreter mockServer 50
2727
-- add 2 blocks with tx
@@ -36,7 +36,7 @@ checkEpochDisabledArg =
3636

3737
checkEpochEnabled :: IOManager -> [(Text, Text)] -> Assertion
3838
checkEpochEnabled =
39-
withCustomConfig (mkCommandLineArgs False) babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
39+
withCustomConfig (mkCommandLineArgs False) Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
4040
startDBSync dbSyncEnv
4141
b1 <- forgeAndSubmitBlocks interpreter mockServer 50
4242
-- add 2 blocks with tx

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/CommandLineArg/ForceIndex.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Test.Tasty.HUnit (Assertion)
1616

1717
checkForceIndexesArg :: IOManager -> [(Text, Text)] -> Assertion
1818
checkForceIndexesArg =
19-
withCustomConfig commandLineForceIndexArgs babbageConfigDir testLabel $ \_ _ dbSyncEnv -> do
19+
withCustomConfig commandLineForceIndexArgs Nothing babbageConfigDir testLabel $ \_ _ dbSyncEnv -> do
2020
startDBSync dbSyncEnv
2121
threadDelay 3_000_000
2222
assertEqQuery dbSyncEnv DB.queryPgIndexesCount 162 "there wasn't the correct number of indexes"
@@ -29,7 +29,7 @@ checkForceIndexesArg =
2929

3030
checkNoForceIndexesArg :: IOManager -> [(Text, Text)] -> Assertion
3131
checkNoForceIndexesArg =
32-
withCustomConfigAndDropDB commandLineNoForceIndexArgs babbageConfigDir testLabel $ \_ _ dbSyncEnv -> do
32+
withCustomConfigAndDropDB commandLineNoForceIndexArgs Nothing babbageConfigDir testLabel $ \_ _ dbSyncEnv -> do
3333
startDBSync dbSyncEnv
3434
threadDelay 3_000_000
3535
assertEqQuery dbSyncEnv DB.queryPgIndexesCount 97 "there wasn't the correct number of indexes"

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/CommandLineArg/MigrateConsumedPruneTxOut.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import Test.Tasty.HUnit (Assertion)
5151

5252
commandLineArgCheck :: IOManager -> [(Text, Text)] -> Assertion
5353
commandLineArgCheck = do
54-
withCustomConfigAndDropDB cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
54+
withCustomConfigAndDropDB cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
5555
void $
5656
withBabbageFindLeaderAndSubmitTx interpreter mockServer $
5757
Babbage.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10000 500
@@ -69,7 +69,7 @@ commandLineArgCheck = do
6969

7070
basicPrune :: IOManager -> [(Text, Text)] -> Assertion
7171
basicPrune = do
72-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
72+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
7373
startDBSync dbSyncEnv
7474
-- add 50 block
7575
b1 <- forgeAndSubmitBlocks interpreter mockServer 50
@@ -98,7 +98,7 @@ basicPrune = do
9898

9999
pruneWithSimpleRollback :: IOManager -> [(Text, Text)] -> Assertion
100100
pruneWithSimpleRollback = do
101-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
101+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
102102
blk0 <- forgeNext interpreter mockBlock0
103103
blk1 <- forgeNext interpreter mockBlock1
104104
atomically $ addBlock mockServer blk0
@@ -128,7 +128,7 @@ pruneWithSimpleRollback = do
128128

129129
pruneWithFullTxRollback :: IOManager -> [(Text, Text)] -> Assertion
130130
pruneWithFullTxRollback = do
131-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
131+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
132132
startDBSync dbSyncEnv
133133
blk0 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
134134
void $ withBabbageFindLeaderAndSubmit interpreter mockServer $ \st -> do
@@ -162,7 +162,7 @@ pruneWithFullTxRollback = do
162162
-- In these tests, 2 x securityParam = 20 blocks.
163163
pruningShouldKeepSomeTx :: IOManager -> [(Text, Text)] -> Assertion
164164
pruningShouldKeepSomeTx = do
165-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
165+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
166166
startDBSync dbSyncEnv
167167
b1 <- forgeAndSubmitBlocks interpreter mockServer 80
168168
-- these two blocs + tx will fall withing the last 20 blocks so should not be pruned
@@ -189,7 +189,7 @@ pruningShouldKeepSomeTx = do
189189
-- prune with rollback
190190
pruneAndRollBackOneBlock :: IOManager -> [(Text, Text)] -> Assertion
191191
pruneAndRollBackOneBlock = do
192-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
192+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
193193
startDBSync dbSyncEnv
194194
void $ forgeAndSubmitBlocks interpreter mockServer 98
195195
-- add 2 blocks with tx
@@ -225,7 +225,7 @@ pruneAndRollBackOneBlock = do
225225
-- consume with rollback
226226
noPruneAndRollBack :: IOManager -> [(Text, Text)] -> Assertion
227227
noPruneAndRollBack = do
228-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
228+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
229229
startDBSync dbSyncEnv
230230
void $ forgeAndSubmitBlocks interpreter mockServer 98
231231
-- add 2 blocks with tx
@@ -260,7 +260,7 @@ noPruneAndRollBack = do
260260

261261
pruneSameBlock :: IOManager -> [(Text, Text)] -> Assertion
262262
pruneSameBlock =
263-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
263+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
264264
startDBSync dbSyncEnv
265265
void $ forgeAndSubmitBlocks interpreter mockServer 76
266266
blk77 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
@@ -289,7 +289,7 @@ pruneSameBlock =
289289

290290
noPruneSameBlock :: IOManager -> [(Text, Text)] -> Assertion
291291
noPruneSameBlock =
292-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
292+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
293293
startDBSync dbSyncEnv
294294
void $ forgeAndSubmitBlocks interpreter mockServer 96
295295
blk97 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
@@ -315,7 +315,7 @@ noPruneSameBlock =
315315

316316
migrateAndPruneRestart :: IOManager -> [(Text, Text)] -> Assertion
317317
migrateAndPruneRestart = do
318-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
318+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
319319
let DBSyncEnv {..} = dbSyncEnv
320320
startDBSync dbSyncEnv
321321
void $ forgeAndSubmitBlocks interpreter mockServer 50
@@ -340,7 +340,7 @@ migrateAndPruneRestart = do
340340

341341
pruneRestartMissingFlag :: IOManager -> [(Text, Text)] -> Assertion
342342
pruneRestartMissingFlag = do
343-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
343+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
344344
let DBSyncEnv {..} = dbSyncEnv
345345

346346
startDBSync dbSyncEnv
@@ -366,7 +366,7 @@ pruneRestartMissingFlag = do
366366

367367
bootstrapRestartMissingFlag :: IOManager -> [(Text, Text)] -> Assertion
368368
bootstrapRestartMissingFlag = do
369-
withCustomConfig cmdLineArgs babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
369+
withCustomConfig cmdLineArgs Nothing babbageConfigDir testLabel $ \interpreter mockServer dbSyncEnv -> do
370370
let DBSyncEnv {..} = dbSyncEnv
371371
startDBSync dbSyncEnv
372372
void $ forgeAndSubmitBlocks interpreter mockServer 50

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/CommandLineArg/ConfigFile.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Prelude ()
1313

1414
checkConfigFileArg :: IOManager -> [(Text, Text)] -> Assertion
1515
checkConfigFileArg =
16-
withCustomConfig cliArgs conwayConfigDir testLabel $ \_ _ dbSync -> do
16+
withCustomConfig cliArgs Nothing conwayConfigDir testLabel $ \_ _ dbSync -> do
1717
startDBSync dbSync
1818
-- There is a slight delay before the flag is checked
1919
threadDelay 2_000_000

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/CommandLineArg/EpochDisabled.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Prelude ()
1818

1919
checkEpochDisabledArg :: IOManager -> [(Text, Text)] -> Assertion
2020
checkEpochDisabledArg =
21-
withCustomConfigAndDropDB cliArgs conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
21+
withCustomConfigAndDropDB cliArgs Nothing conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
2222
startDBSync dbSync
2323

2424
-- Forge some blocks
@@ -42,7 +42,7 @@ checkEpochDisabledArg =
4242

4343
checkEpochEnabled :: IOManager -> [(Text, Text)] -> Assertion
4444
checkEpochEnabled =
45-
withCustomConfig cliArgs conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
45+
withCustomConfig cliArgs Nothing conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
4646
startDBSync dbSync
4747

4848
-- Forge some blocks

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/CommandLineArg/ForceIndex.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Prelude ()
1313

1414
checkForceIndexesArg :: IOManager -> [(Text, Text)] -> Assertion
1515
checkForceIndexesArg =
16-
withCustomConfig cliArgs conwayConfigDir testLabel $ \_ _ dbSync -> do
16+
withCustomConfig cliArgs Nothing conwayConfigDir testLabel $ \_ _ dbSync -> do
1717
startDBSync dbSync
1818

1919
-- Verify number of DB indexes
@@ -24,7 +24,7 @@ checkForceIndexesArg =
2424

2525
checkNoForceIndexesArg :: IOManager -> [(Text, Text)] -> Assertion
2626
checkNoForceIndexesArg =
27-
withCustomConfigAndDropDB cliArgs conwayConfigDir testLabel $ \_ _ dbSync -> do
27+
withCustomConfigAndDropDB cliArgs Nothing conwayConfigDir testLabel $ \_ _ dbSync -> do
2828
startDBSync dbSync
2929

3030
-- Verify number of DB indexes

0 commit comments

Comments
 (0)