-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6052 from IntersectMBO/jutaro/tracer_adds
Enhancements and fixes related to logging, metrics, and testing
- Loading branch information
Showing
5 changed files
with
163 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 51 additions & 26 deletions
77
cardano-node/test/Test/Cardano/Tracing/NewTracing/Consistency.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,67 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
|
||
|
||
-- | Check namespace consistencies agains configurations | ||
module Test.Cardano.Tracing.NewTracing.Consistency (tests) where | ||
|
||
import Cardano.Node.Tracing.Consistency (checkNodeTraceConfiguration) | ||
|
||
import Control.Monad.IO.Class (liftIO) | ||
import Control.Monad.IO.Class (MonadIO) | ||
import Data.Text | ||
import qualified System.Directory as IO | ||
import System.FilePath ((</>)) | ||
|
||
import Hedgehog (Property) | ||
import qualified Hedgehog as H | ||
import qualified Hedgehog.Extras.Test.Base as H.Base | ||
import qualified Hedgehog.Extras.Test.Base as H | ||
import qualified Hedgehog.Extras.Test.Process as H | ||
import Hedgehog.Internal.Property (PropertyName (PropertyName)) | ||
|
||
tests :: IO Bool | ||
tests = H.checkSequential | ||
tests :: MonadIO m => m Bool | ||
tests = do | ||
H.checkSequential | ||
$ H.Group "Configuration Consistency tests" | ||
$ test | ||
<$> [ ( [] | ||
, "goodConfig.yaml") | ||
, ( [ "Config namespace error: Illegal namespace ChainDB.CopyToImmutableDBEvent2.CopiedBlockToImmutableDB" | ||
, "Config namespace error: Illegal namespace SubscriptionDNS" | ||
] | ||
, "badConfig.yaml") | ||
-- TODO: add mainnet config as good | ||
] | ||
$ Prelude.map test | ||
[ ( [] | ||
-- This file name should reference the current standard config with new tracing | ||
, configSubdir | ||
, "mainnet-config-new-tracing.json" | ||
) | ||
, | ||
( [] | ||
, testSubdir | ||
, "goodConfig.yaml" | ||
) | ||
, ( [ "Config namespace error: Illegal namespace ChainDB.CopyToImmutableDBEvent2.CopiedBlockToImmutableDB" | ||
, "Config namespace error: Illegal namespace SubscriptionDNS" | ||
] | ||
, testSubdir | ||
, "badConfig.yaml" | ||
) | ||
] | ||
where | ||
test (actualValue, goldenBaseName) = | ||
(PropertyName goldenBaseName, goldenTestJSON actualValue goldenBaseName) | ||
test (actualValue, subDir, goldenBaseName) = | ||
(PropertyName goldenBaseName, goldenTestJSON subDir actualValue goldenBaseName) | ||
|
||
goldenTestJSON :: SubdirSelection -> [Text] -> FilePath -> Property | ||
goldenTestJSON subDir expectedOutcome goldenFileBaseName = | ||
H.withTests 1 $ H.withShrinks 0 $ H.property $ do | ||
base <- resolveDir | ||
goldenFp <- H.note $ base </> goldenFileBaseName | ||
actualValue <- H.evalIO $ checkNodeTraceConfiguration goldenFp | ||
actualValue H.=== expectedOutcome | ||
where | ||
resolveDir = case subDir of | ||
ExternalSubdir d -> do | ||
base <- H.evalIO . IO.canonicalizePath =<< H.getProjectBase | ||
pure $ base </> d | ||
InternalSubdir d -> | ||
pure d | ||
|
||
goldenTestJSON :: [Text] -> FilePath -> Property | ||
goldenTestJSON expectedOutcome goldenFileBaseName = | ||
H.withTests 1 $ H.withShrinks 0 $ H.property $ do | ||
goldenFp <- H.Base.note $ addPrefix goldenFileBaseName | ||
actualValue <- liftIO $ checkNodeTraceConfiguration goldenFp | ||
actualValue H.=== expectedOutcome | ||
|
||
data SubdirSelection = | ||
InternalSubdir FilePath | ||
| ExternalSubdir FilePath | ||
|
||
-- | NB: this function is only used in 'goldenTestJSON' but it is defined at the | ||
-- top level so that we can refer to it in the documentation of this module. | ||
addPrefix :: FilePath -> FilePath | ||
addPrefix fname = "test/Test/Cardano/Tracing/NewTracing/data/" <> fname | ||
testSubdir, configSubdir :: SubdirSelection | ||
testSubdir = InternalSubdir "test/Test/Cardano/Tracing/NewTracing/data" | ||
configSubdir = ExternalSubdir $ "configuration" </> "cardano" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters