Skip to content

Commit 619687b

Browse files
committed
remote: fix flaky collectGarbage for MITM test
1 parent e374687 commit 619687b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

hnix-store-remote/tests-io/NixDaemonSpec.hs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module NixDaemonSpec
55
, spec
66
) where
77

8+
import Control.Exception (catch, SomeException)
89
import Control.Monad (forM_, unless, void)
910
import Control.Monad.Catch (MonadMask)
1011
import Control.Monad.Conc.Class (MonadConc)
@@ -465,13 +466,17 @@ makeProtoSpec f flavor = around f $ do
465466
-- clear temp gc roots so the delete works. restarting the nix daemon should also do this...
466467
storeDir <- getStoreDir
467468
let tempRootsDir = Data.Text.unpack $ mconcat [ Data.Text.Encoding.decodeUtf8 (unStoreDir storeDir), "/../var/nix/temproots/" ]
468-
tempRootList <-
469-
liftIO
470-
$ System.Directory.listDirectory
471-
tempRootsDir
472-
liftIO $ forM_ tempRootList $ \entry -> do
473-
System.Directory.removeFile
474-
$ mconcat [ tempRootsDir, "/", entry ]
469+
liftIO $ do
470+
tempRootList <-
471+
System.Directory.listDirectory tempRootsDir
472+
forM_ tempRootList $ \entry -> do
473+
System.Directory.removeFile
474+
$ mconcat [ tempRootsDir, "/", entry ]
475+
-- for MITM, the temp root will get deleted
476+
-- by the daemon as our nested client exists
477+
-- but the listDirectory might still see it
478+
-- causing TOC/TOU flakiness
479+
`catch` (\(_e :: SomeException) -> pure ())
475480

476481
GCResult{..} <-
477482
collectGarbage

0 commit comments

Comments
 (0)