Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/Hedgehog/Extras/Test/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import qualified System.Environment as IO
import qualified System.Info as IO
import qualified System.IO as IO
import qualified System.IO.Temp as IO
import qualified System.Timeout as IO

{- HLINT ignore "Reduce duplication" -}

Expand Down Expand Up @@ -208,17 +209,19 @@ workspace prefixPath f =
=> FilePath
-> Int
-> m ()
removeWorkspaceRetries ws retries = GHC.withFrozenCallStack $ do
result <- try (liftIO (IO.removePathForcibly ws))
case result of
Right () -> return ()
Left (_ :: IOException) -> do
if retries > 0
then do
liftIO (IO.threadDelay 100000) -- wait 100ms before retrying
removeWorkspaceRetries ws (retries - 1)
else do
failMessage GHC.callStack "Failed to remove workspace directory after multiple attempts"
removeWorkspaceRetries ws retries =
GHC.withFrozenCallStack $ do
result <- try (liftIO (IO.timeout (5 * 1000) (IO.removePathForcibly ws)))
case result of
Right (Just ()) -> return ()
Right Nothing -> pure ()
Left (_ :: IOException) -> do
Comment on lines +213 to +218
Copy link
Contributor

@carbolymer carbolymer Jun 30, 2025

Choose a reason for hiding this comment

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

Readability could be improved here:

Suggested change
GHC.withFrozenCallStack $ do
result <- try (liftIO (IO.timeout (5 * 1000) (IO.removePathForcibly ws)))
case result of
Right (Just ()) -> return ()
Right Nothing -> pure ()
Left (_ :: IOException) -> do
GHC.withFrozenCallStack $ do
catch
(timeout (5_000) (liftIO $ IO.removePathForcibly ws))
$ \(_ :: IOException) -> do

from lifted-base: catch, timeout.

5 ms seems to be not much here. I'd increase it an order of magnitude, just to be on the safe side.

if retries > 0
then do
liftIO (IO.threadDelay 100000) -- wait 100ms before retrying
Copy link
Contributor

@carbolymer carbolymer Jun 30, 2025

Choose a reason for hiding this comment

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

Suggestion: use lifted-base:

Suggested change
liftIO (IO.threadDelay 100000) -- wait 100ms before retrying
threadDelay 100_000 -- wait 100ms before retrying

removeWorkspaceRetries ws (retries - 1)
else do
failMessage GHC.callStack "Failed to remove workspace directory after multiple attempts"


-- | Create a workspace directory which will exist for at least the duration of
Expand Down
Loading