Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomize test-ghc-env to avoid conflicts between parallel jobs #5757

Merged
merged 8 commits into from
Aug 16, 2022

Conversation

zyla
Copy link
Contributor

@zyla zyla commented May 27, 2022

Since the build temporary directory is shared between parallel jobs, we can't use
the same file name for the test-ghc-env for all of them. This PR uses a random name for each parallel job to avoid conflicts.

Fixes #5024

  • Any changes that could be relevant to users have been recorded in the ChangeLog.md
  • The documentation has been updated, if necessary.

zyla added 3 commits October 27, 2021 12:23
Since the build temporary directory is shared between jobs, we can't use
the same file name for the `test-ghc-env` for all of them.

Fixes commercialhaskell#5024
@zyla zyla changed the title Random test ghc env Randomize test-ghc-env to avoid conflicts between parallel jobs May 27, 2022
Comment on lines 1929 to 1936
-- see e.g. https://github.com/doctest/issues/119
-- also we set HASKELL_DIST_DIR to a package dist directory so
-- doctest will be able to load modules autogenerated by Cabal
ghcEnvRandomId <- liftIO (randomIO :: IO Int)
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
fp = toFilePath (eeTempDir ee </> testGhcEnvRelFile) <> show ghcEnvRandomId
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ghcEnvRandomId line interjects the preceding multiline comment explaining env variables and the next line, let setEnv ... — to which that comment is relevant. Please move somewhere else.

Perhaps like this?

                -- see e.g. https://github.com/doctest/issues/119
                -- also we set HASKELL_DIST_DIR to a package dist directory so
                -- doctest will be able to load modules autogenerated by Cabal
                let setEnv f pc = modifyEnvVars pc $ \envVars ->
                      Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePath buildDir) $
                      Map.insert "GHC_ENVIRONMENT" (T.pack f) envVars
+               ghcEnvRandomId <- liftIO (randomIO :: IO Int)
-                   fp = toFilePath $ eeTempDir ee </> testGhcEnvRelFile
+               let fp = toFilePath (eeTempDir ee </> testGhcEnvRelFile) <> show ghcEnvRandomId

Further, it's not so hard to stay within typed Path, just import addExtension:

-               ghcEnvRandomId <- liftIO (randomIO :: IO Int)
-               let fp = toFilePath $ eeTempDir ee </> testGhcEnvRelFile
+               randomSuffix <- ("-"<>) . show <$> liftIO (randomIO :: IO Int)
+               fp <- toFilePath <$> addExtension randomSuffix (eeTempDir ee </> testGhcEnvRelFile)

@mpilgrem mpilgrem merged commit 348f8e0 into commercialhaskell:master Aug 16, 2022
@mpilgrem
Copy link
Member

Thanks! @zyla and @ulidtko, I have merged this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-deterministic test suite execution failures
3 participants