Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7df2e36

Browse files
committed
Set the XDG_CACHE_HOME for tests
This makes sure each test run is independent. Makes the tests * iface-error-test-1 * iface-th-test less flaky locally. Should not have any effect on the CI flakiness issue.
1 parent 173b5a7 commit 7df2e36

File tree

1 file changed

+27
-5
lines changed
  • hls-test-utils/src/Test

1 file changed

+27
-5
lines changed

‎hls-test-utils/src/Test/Hls.hs‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,23 +516,45 @@ runWithLockInTempDir tree act = withLock lockForTempDirs $ do
516516
cleanupTempDir <- lookupEnv "HLS_TEST_HARNESS_NO_TESTDIR_CLEANUP"
517517
let runTestInDir action = case cleanupTempDir of
518518
Just val | val /= "0" -> do
519-
(tempDir, _) <- newTempDirWithin testRoot
520-
a <- action tempDir
519+
(tempDir, cacheHome, _) <- setupTemporaryTestDirectories testRoot
520+
a <- withTempCacheHome cacheHome (action tempDir)
521521
logWith helperRecorder Debug LogNoCleanup
522522
pure a
523523

524524
_ -> do
525-
(tempDir, cleanup) <- newTempDirWithin testRoot
526-
a <- action tempDir `finally` cleanup
525+
(tempDir, cacheHome, cleanup) <- setupTemporaryTestDirectories testRoot
526+
a <- withTempCacheHome cacheHome (action tempDir) `finally` cleanup
527527
logWith helperRecorder Debug LogCleanup
528528
pure a
529529
runTestInDir $ \tmpDir' -> do
530530
-- we canonicalize the path, so that we do not need to do
531-
-- cannibalization during the test when we compare two paths
531+
-- canonicalization during the test when we compare two paths
532532
tmpDir <- canonicalizePath tmpDir'
533533
logWith helperRecorder Info $ LogTestDir tmpDir
534534
fs <- FS.materialiseVFT tmpDir tree
535535
act fs
536+
where
537+
cache_home_var = "XDG_CACHE_HOME"
538+
-- Set the dir for "XDG_CACHE_HOME".
539+
-- When the operation finished, make sure the old value is restored.
540+
withTempCacheHome tempCacheHomeDir act =
541+
bracket
542+
(do
543+
old_cache_home <- lookupEnv cache_home_var
544+
setEnv cache_home_var tempCacheHomeDir
545+
pure old_cache_home)
546+
(\old_cache_home ->
547+
maybe (pure ()) (setEnv cache_home_var) old_cache_home
548+
)
549+
(\_ -> act)
550+
551+
-- Set up a temporary directory for the test files and one for the 'XDG_CACHE_HOME'.
552+
-- The 'XDG_CACHE_HOME' is important for independent test runs, i.e. completely empty
553+
-- caches.
554+
setupTemporaryTestDirectories testRoot = do
555+
(tempTestCaseDir, cleanup1) <- newTempDirWithin testRoot
556+
(tempCacheHomeDir, cleanup2) <- newTempDirWithin testRoot
557+
pure (tempTestCaseDir, tempCacheHomeDir, cleanup1 >> cleanup2)
536558

537559
runSessionWithServer :: Pretty b => Config -> PluginTestDescriptor b -> FilePath -> Session a -> IO a
538560
runSessionWithServer config plugin fp act =

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /