From 4c273d3b1aae7d68f8a6c312289ddff408e69648 Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Mon, 10 Nov 2025 10:22:06 -0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=88=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 4e7e49d0ff4908c75e39e96f9d2bcb6f77ff18c3 Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Mon, 10 Nov 2025 10:22:00 -0800 Subject: [PATCH 2/3] work around thread delay bug --- .../Test/Consensus/PeerSimulator/Run.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Run.hs b/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Run.hs index 2bb1c13a97..19dd66bd48 100644 --- a/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Run.hs +++ b/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/PeerSimulator/Run.hs @@ -255,11 +255,19 @@ smartDelay :: smartDelay lifecycle@NodeLifecycle{nlStart, nlShutdown} node duration | itIsTimeToRestartTheNode lifecycle duration = do results <- nlShutdown node - threadDelay duration + delay duration nlStart results -smartDelay _ node duration = do - threadDelay duration - pure node + | otherwise = do + delay duration + pure node + +-- This 'threadDelay' operates over 'DiffTime', which has /picosecond/ +-- precision. But 'Control.Concurrent.threadDelay' has only /microsecond/ +-- precision. Thus we must ensure the duration is at least one microsecond; +-- otherwise we will get different results in 'IO' than we do in @io-sim@. +-- See io-sim#232 for more details. +delay :: MonadDelay m => DiffTime -> m () +delay = threadDelay . max 1e-6 itIsTimeToRestartTheNode :: NodeLifecycle blk m -> DiffTime -> Bool itIsTimeToRestartTheNode NodeLifecycle{nlMinDuration} duration = @@ -342,7 +350,7 @@ runScheduler tracer varHandles ps@PointSchedule{psMinEndTime} peers lifecycle@No -- Give an opportunity to the node to finish whatever it was doing at -- shutdown when (itIsTimeToRestartTheNode lifecycle duration) $ - threadDelay $ + delay $ coerce psMinEndTime pure nodeEnd' Nothing -> From a5de257a3f030f7c6e5fa9707a1265db73550ff5 Mon Sep 17 00:00:00 2001 From: Sandy Maguire Date: Mon, 10 Nov 2025 10:22:00 -0800 Subject: [PATCH 3/3] fix: work around thread delay bug