Skip to content

Commit 348f8e0

Browse files
authored
Merge pull request #5757 from zyla/random-test-ghc-env
Randomize `test-ghc-env` to avoid conflicts between parallel jobs
2 parents 4749864 + 0c168c7 commit 348f8e0

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Bug fixes:
5858
[5792](https://github.com/commercialhaskell/stack/issues/5792).
5959
* Fixed output of `stack ls snapshots local` on Windows, to behave like that on
6060
Unix-like operating systems.
61+
* Fix non-deterministic test failures when executing a test suite for a
62+
multi-project repository with parallelism enabled. See
63+
[#5024](https://github.com/commercialhaskell/stack/issues/5024)
6164

6265
## v2.7.5
6366

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ dependencies:
110110
- primitive
111111
- process >= 1.6.13.2
112112
- project-template
113+
- random
113114
- retry
114115
- rio >= 0.1.22.0
115116
- rio-prettyprint >= 0.1.1.0

src/Stack/Build/Execute.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import System.PosixCompat.Files (createLink, modificationTime, getFile
9595
import RIO.PrettyPrint
9696
import RIO.Process
9797
import Pantry.Internal.Companion
98+
import System.Random (randomIO)
9899

99100
-- | Has an executable been built or not?
100101
data ExecutableBuildStatus
@@ -1930,8 +1931,13 @@ singleTest topts testsToRun ac ee task installedMap = do
19301931
let setEnv f pc = modifyEnvVars pc $ \envVars ->
19311932
Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePath buildDir) $
19321933
Map.insert "GHC_ENVIRONMENT" (T.pack f) envVars
1933-
fp = toFilePath $ eeTempDir ee </> testGhcEnvRelFile
1934-
snapDBPath = toFilePathNoTrailingSep (bcoSnapDB $ eeBaseConfigOpts ee)
1934+
fp' = eeTempDir ee </> testGhcEnvRelFile
1935+
-- Add a random suffix to avoid conflicts between parallel jobs
1936+
-- See https://github.com/commercialhaskell/stack/issues/5024
1937+
randomInt <- liftIO (randomIO :: IO Int)
1938+
let randomSuffix = "." <> show (abs randomInt)
1939+
fp <- toFilePath <$> addExtension randomSuffix fp'
1940+
let snapDBPath = toFilePathNoTrailingSep (bcoSnapDB $ eeBaseConfigOpts ee)
19351941
localDBPath = toFilePathNoTrailingSep (bcoLocalDB $ eeBaseConfigOpts ee)
19361942
ghcEnv =
19371943
"clear-package-db\n" <>

stack.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ library
286286
, primitive
287287
, process >=1.6.13.2
288288
, project-template
289+
, random
289290
, retry
290291
, rio >=0.1.22.0
291292
, rio-prettyprint >=0.1.1.0
@@ -409,6 +410,7 @@ executable stack
409410
, primitive
410411
, process >=1.6.13.2
411412
, project-template
413+
, random
412414
, retry
413415
, rio >=0.1.22.0
414416
, rio-prettyprint >=0.1.1.0
@@ -533,6 +535,7 @@ executable stack-integration-test
533535
, primitive
534536
, process >=1.6.13.2
535537
, project-template
538+
, random
536539
, retry
537540
, rio >=0.1.22.0
538541
, rio-prettyprint >=0.1.1.0
@@ -662,6 +665,7 @@ test-suite stack-test
662665
, primitive
663666
, process >=1.6.13.2
664667
, project-template
668+
, random
665669
, raw-strings-qq
666670
, retry
667671
, rio >=0.1.22.0

0 commit comments

Comments
 (0)