diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index e6627ebc23..4e7993c9b7 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -313,7 +313,7 @@ test-suite cardano-cli-test Test.Cli.Pipes Test.Cli.Shelley.Run.Query - ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T + ghc-options: -threaded -rtsopts "-with-rtsopts=-N -T" test-suite cardano-cli-golden import: project-config @@ -341,6 +341,8 @@ test-suite cardano-cli-golden , filepath , hedgehog ^>= 1.4 , hedgehog-extras ^>= 0.6.1.0 + , lifted-base + , monad-control , regex-compat , regex-tdfa , tasty @@ -348,6 +350,7 @@ test-suite cardano-cli-golden , text , time , transformers + , transformers-base , unordered-containers build-tool-depends: cardano-cli:cardano-cli , tasty-discover:tasty-discover @@ -420,4 +423,4 @@ test-suite cardano-cli-golden Test.Golden.TxView Test.Golden.Version - ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T + ghc-options: -threaded -rtsopts "-with-rtsopts=-N -T" diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs index ba579f1d2d..2920f9c0c0 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE FlexibleContexts #-} {- HLINT ignore "Use camelCase" -} module Test.Golden.Governance.DRep where @@ -7,7 +8,13 @@ module Test.Golden.Governance.DRep where #define UNIX #endif +import Control.Concurrent (newQSem) +import Control.Concurrent.QSem (QSem, waitQSem, signalQSem) +import Control.Exception.Lifted (bracket_) import Control.Monad +import Control.Monad.Base +import Control.Monad.Trans.Control (MonadBaseControl) +import System.IO.Unsafe (unsafePerformIO) #ifdef UNIX import Data.Bits ((.&.)) @@ -24,6 +31,18 @@ import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Golden as H +-- | Semaphore protecting against locked file error, when running properties concurrently. +-- This semaphore protects @"test/cardano-cli-golden/files/golden/governance/drep/drep_retirement_cert"@. +drepRetirementCertSem :: QSem +drepRetirementCertSem = unsafePerformIO $ newQSem 1 +{-# NOINLINE drepRetirementCertSem #-} + +-- | Semaphore protecting against locked file error, when running properties concurrently. +-- This semaphore protects @"test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate.json"@. +drepRegistrationCertSem :: QSem +drepRegistrationCertSem = unsafePerformIO $ newQSem 1 +{-# NOINLINE drepRegistrationCertSem #-} + hprop_golden_governanceDRepKeyGen :: Property hprop_golden_governanceDRepKeyGen = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do @@ -92,8 +111,8 @@ hprop_golden_governance_drep_extended_key_signing = skeyFile <- noteInputFile "test/cardano-cli-golden/files/input/governance/drep/extended-key-signing/drep.skey" txBody <- noteInputFile "test/cardano-cli-golden/files/input/governance/drep/extended-key-signing/tx.body" - outGold <- H.note "test/cardano-cli-golden/files/golden/governance/drep/extended-key-signing/tx.signed" outFile <- H.noteTempFile tempDir "outFile" + outGold <- H.note "test/cardano-cli-golden/files/golden/governance/drep/extended-key-signing/tx.signed" void $ execCardanoCLI [ "conway", "transaction", "sign" @@ -118,7 +137,8 @@ hprop_golden_governance_drep_retirement_certificate_vkey_file = , "--out-file", certFile ] - H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile + bracketSem drepRetirementCertSem $ + H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile hprop_golden_governance_drep_retirement_certificate_id_hex :: Property hprop_golden_governance_drep_retirement_certificate_id_hex = @@ -135,7 +155,8 @@ hprop_golden_governance_drep_retirement_certificate_id_hex = , "--out-file", certFile ] - H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile + bracketSem drepRetirementCertSem $ + H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile hprop_golden_governance_drep_retirement_certificate_id_bech32 :: Property hprop_golden_governance_drep_retirement_certificate_id_bech32 = @@ -152,7 +173,8 @@ hprop_golden_governance_drep_retirement_certificate_id_bech32 = , "--out-file", certFile ] - H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile + bracketSem drepRetirementCertSem $ + H.diffFileVsGoldenFile certFile goldenDRepRetirementCertFile hprop_golden_governance_drep_metadata_hash :: Property hprop_golden_governance_drep_metadata_hash = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do @@ -187,12 +209,13 @@ hprop_golden_governance_drep_registration_certificate_vkey_file = propertyOnce . , "--out-file", outFile ] - H.diffFileVsGoldenFile outFile goldenFile + bracketSem drepRegistrationCertSem $ + H.diffFileVsGoldenFile outFile goldenFile hprop_golden_governance_drep_registration_certificate_id_hex :: Property hprop_golden_governance_drep_registration_certificate_id_hex = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do - goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate.json" idFile <- H.readFile "test/cardano-cli-golden/files/input/drep.id.hex" + goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate.json" outFile <- H.noteTempFile tempDir "drep-reg-cert.txt" @@ -205,12 +228,13 @@ hprop_golden_governance_drep_registration_certificate_id_hex = propertyOnce . H. , "--out-file", outFile ] - H.diffFileVsGoldenFile outFile goldenFile + bracketSem drepRegistrationCertSem $ + H.diffFileVsGoldenFile outFile goldenFile hprop_golden_governance_drep_registration_certificate_id_bech32 :: Property hprop_golden_governance_drep_registration_certificate_id_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do - goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate.json" idFile <- H.readFile "test/cardano-cli-golden/files/input/drep.id.bech32" + goldenFile <- H.note "test/cardano-cli-golden/files/golden/governance/drep/drep_registration_certificate.json" outFile <- H.noteTempFile tempDir "drep-reg-cert.txt" @@ -223,7 +247,8 @@ hprop_golden_governance_drep_registration_certificate_id_bech32 = propertyOnce . , "--out-file", outFile ] - H.diffFileVsGoldenFile outFile goldenFile + bracketSem drepRegistrationCertSem $ + H.diffFileVsGoldenFile outFile goldenFile hprop_golden_governance_drep_registration_certificate_script_hash :: Property hprop_golden_governance_drep_registration_certificate_script_hash = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do @@ -260,3 +285,8 @@ hprop_golden_governance_drep_update_certificate_vkey_file = propertyOnce . H.mod ] H.diffFileVsGoldenFile outFile goldenFile + +-- | Run action acquiring a semaphore, and releasing afterwards. Allows to guard against concurrent access to +-- a block of code +bracketSem :: MonadBaseControl IO m => QSem -> m c -> m c +bracketSem semaphore = bracket_ (liftBase $ waitQSem semaphore) (liftBase $ signalQSem semaphore)