remote: fix flaky collectGarbage for MITM test

This commit is contained in:
sorki 2023-12-12 07:08:17 +01:00
parent e374687467
commit 619687b446

View File

@ -5,6 +5,7 @@ module NixDaemonSpec
, spec , spec
) where ) where
import Control.Exception (catch, SomeException)
import Control.Monad (forM_, unless, void) import Control.Monad (forM_, unless, void)
import Control.Monad.Catch (MonadMask) import Control.Monad.Catch (MonadMask)
import Control.Monad.Conc.Class (MonadConc) import Control.Monad.Conc.Class (MonadConc)
@ -465,13 +466,17 @@ makeProtoSpec f flavor = around f $ do
-- clear temp gc roots so the delete works. restarting the nix daemon should also do this... -- clear temp gc roots so the delete works. restarting the nix daemon should also do this...
storeDir <- getStoreDir storeDir <- getStoreDir
let tempRootsDir = Data.Text.unpack $ mconcat [ Data.Text.Encoding.decodeUtf8 (unStoreDir storeDir), "/../var/nix/temproots/" ] let tempRootsDir = Data.Text.unpack $ mconcat [ Data.Text.Encoding.decodeUtf8 (unStoreDir storeDir), "/../var/nix/temproots/" ]
tempRootList <- liftIO $ do
liftIO tempRootList <-
$ System.Directory.listDirectory System.Directory.listDirectory tempRootsDir
tempRootsDir forM_ tempRootList $ \entry -> do
liftIO $ forM_ tempRootList $ \entry -> do System.Directory.removeFile
System.Directory.removeFile $ mconcat [ tempRootsDir, "/", entry ]
$ mconcat [ tempRootsDir, "/", entry ] -- for MITM, the temp root will get deleted
-- by the daemon as our nested client exists
-- but the listDirectory might still see it
-- causing TOC/TOU flakiness
`catch` (\(_e :: SomeException) -> pure ())
GCResult{..} <- GCResult{..} <-
collectGarbage collectGarbage