Skip to content

Commit 86bbbfb

Browse files
PLT-9261 possible fix and debug for intermittent darwin failure (#291)
1 parent cc322d6 commit 86bbbfb

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

marconi-core/test/Marconi/CoreSpec.hs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ import Control.Concurrent.STM (
131131
TBQueue,
132132
newTBQueueIO,
133133
)
134-
import Control.Exception (bracket)
134+
import Control.Exception (SomeException, bracket, try)
135135
import Control.Lens (
136136
Getter,
137137
Lens',
@@ -156,6 +156,7 @@ import Control.Monad.Trans.Class (lift)
156156
import Control.Monad.Trans.Except (ExceptT)
157157
import Control.Monad.Trans.State (StateT, evalStateT, gets)
158158
import Control.Tracer qualified as Tracer
159+
import Data.Bifunctor (first)
159160
import Data.ByteString qualified as BS
160161
import Data.Either (fromRight)
161162
import Data.Foldable (Foldable (foldl'), find)
@@ -1728,23 +1729,33 @@ propWithStreamTBQueue = monadicExceptTIO @() $ GenM.forAllM genChainWithInstabil
17281729
such that the client can consume from the socket as a stream.
17291730
-}
17301731
propWithStreamSocket :: Property
1731-
propWithStreamSocket = monadicExceptTIO @() $
1732-
GenM.forAllM genChainWithInstability $ \args -> do
1733-
(_, (actual, expected)) <- liftIO
1734-
$ Tmp.withSystemTempDirectory
1735-
mempty
1736-
$ \dir -> do
1737-
let chainSubset = take (chainSizeSubset args) (eventGenerator args)
1738-
-- We need to make the filename as short as possible, because we're very limited by path
1739-
-- length
1740-
fileName = dir </> "f"
1741-
serverStarted <- newQSem 1
1742-
concurrently
1732+
propWithStreamSocket = monadicExceptTIO @() $ GenM.forAllM genChainWithInstability $ \args -> do
1733+
res <- liftIO $ Tmp.withSystemTempDirectory "a" $ \dir -> do
1734+
-- We need to make the filename as short as possible, because we're very limited by socket
1735+
-- path length.
1736+
let
1737+
fileName = dir </> "f"
1738+
failMsg = "\nSocket path: " <> fileName
1739+
1740+
first ((<> failMsg) . show) <$> try @SomeException (runTestWithSocketFile args fileName)
1741+
1742+
-- Swallowing the error and letting the test fail with the socket path message
1743+
-- is a workaround to enable reporting the path when the test throws an exception before
1744+
-- completion. 'GenM.monitor' or other failure reporting tools don't fire if an
1745+
-- exception is thrown first, but it can't be put within 'withSystemTempDirectory' since
1746+
-- PropertyM m is not 'MonadMask'. Temporary measure to support PLT-9260.
1747+
case res of
1748+
Left msg -> GenM.assertWith False msg
1749+
Right (actual, expected) -> GenM.stop (actual === expected)
1750+
where
1751+
runTestWithSocketFile args fileName = do
1752+
let chainSubset = take (chainSizeSubset args) (eventGenerator args)
1753+
serverStarted <- newQSem 1
1754+
snd
1755+
<$> concurrently
17431756
(server fileName chainSubset serverStarted)
17441757
(client fileName chainSubset serverStarted)
17451758

1746-
GenM.stop (actual == expected)
1747-
where
17481759
server socketPath chainSubset serverStarted = bracket (runUnixSocketServer socketPath) close $ \s -> do
17491760
signalQSem serverStarted
17501761
(conn, _) <- accept s

0 commit comments

Comments
 (0)