@@ -9,15 +9,16 @@ module Test.Consensus.PeerSimulator.Tests.LinkedThreads (tests) where
99import Control.Monad.Class.MonadAsync (AsyncCancelled (.. ))
1010import Control.Monad.Class.MonadTime.SI (Time (Time ))
1111import Data.Functor (($>) )
12- import Data.Maybe (fromJust )
13- import Ouroboros.Consensus.Util.IOLike (DiffTime , fromException )
12+ import Ouroboros.Consensus.Util.IOLike (fromException )
1413import qualified Ouroboros.Network.AnchoredFragment as AF
1514import Ouroboros.Network.Driver.Limits
1615 (ProtocolLimitFailure (ExceededTimeLimit ))
1716import Ouroboros.Network.Protocol.ChainSync.Codec (mustReplyTimeout )
1817import Test.Consensus.BlockTree (BlockTree (.. ))
1918import Test.Consensus.Genesis.Setup
20- import Test.Consensus.PeerSimulator.Run (defaultSchedulerConfig )
19+ import Test.Consensus.PeerSimulator.Run
20+ (SchedulerConfig (scEnableChainSyncTimeouts ),
21+ defaultSchedulerConfig )
2122import Test.Consensus.PeerSimulator.StateView
2223import Test.Consensus.PointSchedule
2324import Test.Consensus.PointSchedule.Peers (peersOnlyHonest )
@@ -39,13 +40,15 @@ tests = testProperty "ChainSync kills BlockFetch" prop_chainSyncKillsBlockFetch
3940prop_chainSyncKillsBlockFetch :: Property
4041prop_chainSyncKillsBlockFetch = do
4142 forAllGenesisTest
42- (do gt@ GenesisTest {gtChainSyncTimeouts} <- genChains (pure 0 )
43- let schedule = dullSchedule gt (fromJust $ mustReplyTimeout gtChainSyncTimeouts)
44- pure $ gt $> schedule
43+ (do gt@ GenesisTest {gtBlockTree} <- genChains (pure 0 )
44+ pure $ enableMustReplyTimeout $ gt $> dullSchedule (btTrunk gtBlockTree)
4545 )
46- defaultSchedulerConfig
46+
47+ defaultSchedulerConfig {scEnableChainSyncTimeouts = True }
48+
4749 -- No shrinking because the schedule is tiny and hand-crafted
4850 (\ _ _ -> [] )
51+
4952 ( \ _ stateView@ StateView {svTipBlock} ->
5053 svTipBlock == Nothing
5154 && case exceptionsByComponent ChainSyncClient stateView of
@@ -62,9 +65,11 @@ prop_chainSyncKillsBlockFetch = do
6265 _ -> False
6366 )
6467 where
65- dullSchedule :: GenesisTest blk () -> DiffTime -> PointSchedule blk
66- dullSchedule GenesisTest {gtBlockTree} timeout =
67- let (firstBlock, secondBlock) = case AF. toOldestFirst $ btTrunk gtBlockTree of
68+ timeout = 10
69+
70+ dullSchedule :: AF. AnchoredFragment blk -> PointSchedule blk
71+ dullSchedule trunk =
72+ let (firstBlock, secondBlock) = case AF. toOldestFirst trunk of
6873 b1 : b2 : _ -> (b1, b2)
6974 _ -> error " block tree must have two blocks"
7075 psSchedule = peersOnlyHonest $
@@ -73,3 +78,6 @@ prop_chainSyncKillsBlockFetch = do
7378 ]
7479 psMinEndTime = Time $ timeout + 1
7580 in PointSchedule {psSchedule, psStartOrder = [] , psMinEndTime}
81+
82+ enableMustReplyTimeout :: GenesisTest blk schedule -> GenesisTest blk schedule
83+ enableMustReplyTimeout gt = gt { gtChainSyncTimeouts = (gtChainSyncTimeouts gt) { mustReplyTimeout = Just timeout } }
0 commit comments