55{-# LANGUAGE GADTs #-}
66{-# LANGUAGE GeneralizedNewtypeDeriving #-}
77{-# LANGUAGE KindSignatures #-}
8+ {-# LANGUAGE NumericUnderscores #-}
89{-# LANGUAGE RankNTypes #-}
910{-# LANGUAGE ScopedTypeVariables #-}
1011
@@ -21,6 +22,7 @@ module Test.Consensus.MiniProtocol.ObjectDiffusion.Smoke
2122 , prop_smoke_object_diffusion
2223 ) where
2324
25+ import Control.Monad (void )
2426import Control.Monad.IOSim (runSimStrictShutdown )
2527import Control.ResourceRegistry (forkLinkedThread , waitAnyThread , withRegistry )
2628import Control.Tracer (Tracer , nullTracer , traceWith )
@@ -257,9 +259,27 @@ prop_smoke_object_diffusion
257259 let tracer = nullTracer
258260
259261 traceWith tracer " ========== [ Starting ObjectDiffusion smoke test ] =========="
262+ traceWith tracer " objects: "
260263 traceWith tracer (show objects)
261264
262265 (outboundPoolReader, inboundPoolWriter, getAllInboundPoolContent) <- mkPoolInterfaces
266+
267+ -- We wait until the inbound pool content stabilizes
268+ -- Caveat: in the case where objects are continuously added to the
269+ -- outbound pool, this may never terminate.
270+ let waitUntilSettlement prevValue = do
271+ -- TODO: should have a delay value equal to 4·Δ + Ɛ
272+ -- were Δ is the delay in which any message is delivered on the
273+ -- network and Ɛ is a small margin to encompass computation time;
274+ -- as in the worst case, we need 4 echanged messages
275+ -- (+ computation time, assumed negligible w.r.t. network delays)
276+ -- to see a state update on the inbound side
277+ threadDelay 10_000
278+ newValue <- getAllInboundPoolContent
279+ if newValue == prevValue
280+ then pure ()
281+ else waitUntilSettlement newValue
282+
263283 controlMessage <- uncheckedNewTVarM Continue
264284
265285 let
@@ -289,16 +309,15 @@ prop_smoke_object_diffusion
289309 inboundThread <-
290310 forkLinkedThread reg " ObjectDiffusion Inbound peer thread" $
291311 runInboundPeer inbound inboundChannel tracer
292- controlMessageThread <- forkLinkedThread reg " ObjectDiffusion Control thread" $ do
293- threadDelay 1000 -- give a head start to the other threads
294- atomically $ writeTVar controlMessage Terminate
295- threadDelay 1000 -- wait for the other threads to finish
296- waitAnyThread [outboundThread, inboundThread, controlMessageThread]
312+
313+ void $ waitUntilSettlement []
314+ atomically $ writeTVar controlMessage Terminate
315+ waitAnyThread [outboundThread, inboundThread]
297316
298317 traceWith tracer " ========== [ ObjectDiffusion smoke test finished ] =========="
299- poolContent <- getAllInboundPoolContent
300318
301- traceWith tracer " inboundPoolContent:"
319+ poolContent <- getAllInboundPoolContent
320+ traceWith tracer " inboundPoolContent: "
302321 traceWith tracer (show poolContent)
303322 traceWith tracer " ========== ======================================= =========="
304323 pure poolContent
0 commit comments