diff --git a/ChangeLog.md b/ChangeLog.md index 587547c42c..e5c85b40ad 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -58,6 +58,9 @@ Bug fixes: [5792](https://github.com/commercialhaskell/stack/issues/5792). * Fixed output of `stack ls snapshots local` on Windows, to behave like that on Unix-like operating systems. +* Fix non-deterministic test failures when executing a test suite for a + multi-project repository with parallelism enabled. See + [#5024](https://github.com/commercialhaskell/stack/issues/5024) ## v2.7.5 diff --git a/package.yaml b/package.yaml index 06e73ff5c0..77e14e5850 100644 --- a/package.yaml +++ b/package.yaml @@ -110,6 +110,7 @@ dependencies: - primitive - process >= 1.6.13.2 - project-template +- random - retry - rio >= 0.1.22.0 - rio-prettyprint >= 0.1.1.0 diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index 4ca9bab62b..9ef3257de6 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -95,6 +95,7 @@ import System.PosixCompat.Files (createLink, modificationTime, getFile import RIO.PrettyPrint import RIO.Process import Pantry.Internal.Companion +import System.Random (randomIO) -- | Has an executable been built or not? data ExecutableBuildStatus @@ -1930,8 +1931,13 @@ singleTest topts testsToRun ac ee task installedMap = do let setEnv f pc = modifyEnvVars pc $ \envVars -> Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePath buildDir) $ Map.insert "GHC_ENVIRONMENT" (T.pack f) envVars - fp = toFilePath $ eeTempDir ee testGhcEnvRelFile - snapDBPath = toFilePathNoTrailingSep (bcoSnapDB $ eeBaseConfigOpts ee) + fp' = eeTempDir ee testGhcEnvRelFile + -- Add a random suffix to avoid conflicts between parallel jobs + -- See https://github.com/commercialhaskell/stack/issues/5024 + randomInt <- liftIO (randomIO :: IO Int) + let randomSuffix = "." <> show (abs randomInt) + fp <- toFilePath <$> addExtension randomSuffix fp' + let snapDBPath = toFilePathNoTrailingSep (bcoSnapDB $ eeBaseConfigOpts ee) localDBPath = toFilePathNoTrailingSep (bcoLocalDB $ eeBaseConfigOpts ee) ghcEnv = "clear-package-db\n" <> diff --git a/stack.cabal b/stack.cabal index 12cc63a3fc..f7bbb1c1a0 100644 --- a/stack.cabal +++ b/stack.cabal @@ -286,6 +286,7 @@ library , primitive , process >=1.6.13.2 , project-template + , random , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.1.0 @@ -409,6 +410,7 @@ executable stack , primitive , process >=1.6.13.2 , project-template + , random , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.1.0 @@ -533,6 +535,7 @@ executable stack-integration-test , primitive , process >=1.6.13.2 , project-template + , random , retry , rio >=0.1.22.0 , rio-prettyprint >=0.1.1.0 @@ -662,6 +665,7 @@ test-suite stack-test , primitive , process >=1.6.13.2 , project-template + , random , raw-strings-qq , retry , rio >=0.1.22.0