Skip to content

Commit

Permalink
Merge pull request #5757 from zyla/random-test-ghc-env
Browse files Browse the repository at this point in the history
Randomize `test-ghc-env` to avoid conflicts between parallel jobs
  • Loading branch information
mpilgrem authored Aug 16, 2022
2 parents 4749864 + 0c168c7 commit 348f8e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" <>
Expand Down
4 changes: 4 additions & 0 deletions stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 348f8e0

Please sign in to comment.