From 619687b4469d54192a1586dee13eeb7ebf697b2f Mon Sep 17 00:00:00 2001 From: sorki Date: Tue, 12 Dec 2023 07:08:17 +0100 Subject: [PATCH] remote: fix flaky collectGarbage for MITM test --- hnix-store-remote/tests-io/NixDaemonSpec.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hnix-store-remote/tests-io/NixDaemonSpec.hs b/hnix-store-remote/tests-io/NixDaemonSpec.hs index d91848a..ee2e4e7 100644 --- a/hnix-store-remote/tests-io/NixDaemonSpec.hs +++ b/hnix-store-remote/tests-io/NixDaemonSpec.hs @@ -5,6 +5,7 @@ module NixDaemonSpec , spec ) where +import Control.Exception (catch, SomeException) import Control.Monad (forM_, unless, void) import Control.Monad.Catch (MonadMask) 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... storeDir <- getStoreDir let tempRootsDir = Data.Text.unpack $ mconcat [ Data.Text.Encoding.decodeUtf8 (unStoreDir storeDir), "/../var/nix/temproots/" ] - tempRootList <- - liftIO - $ System.Directory.listDirectory - tempRootsDir - liftIO $ forM_ tempRootList $ \entry -> do - System.Directory.removeFile - $ mconcat [ tempRootsDir, "/", entry ] + liftIO $ do + tempRootList <- + System.Directory.listDirectory tempRootsDir + forM_ tempRootList $ \entry -> do + System.Directory.removeFile + $ 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{..} <- collectGarbage