@@ -72,6 +72,7 @@ import Ouroboros.Consensus.Util hiding (Some)
7272import Ouroboros.Consensus.Util.Args
7373import Ouroboros.Consensus.Util.IOLike
7474import qualified Ouroboros.Network.AnchoredSeq as AS
75+ import Ouroboros.Network.Protocol.LocalStateQuery.Type
7576import qualified System.Directory as Dir
7677import System.FS.API
7778import qualified System.FS.IO as FSIO
@@ -280,6 +281,9 @@ instance StateModel Model where
280281 Action Model (ExtLedgerState TestBlock EmptyMK , ExtLedgerState TestBlock EmptyMK )
281282 Init :: SecurityParam -> Action Model ()
282283 ValidateAndCommit :: Word64 -> [TestBlock ] -> Action Model ()
284+ -- \| This action is used only to observe the side effects of closing an
285+ -- uncommitted forker, to ensure all handles are properly deallocated.
286+ OpenAndCloseForker :: Action Model ()
283287
284288 actionName WipeLedgerDB {} = " WipeLedgerDB"
285289 actionName TruncateSnapshots {} = " TruncateSnapshots"
@@ -288,6 +292,7 @@ instance StateModel Model where
288292 actionName GetState {} = " GetState"
289293 actionName Init {} = " Init"
290294 actionName ValidateAndCommit {} = " ValidateAndCommit"
295+ actionName OpenAndCloseForker = " OpenAndCloseForker"
291296
292297 arbitraryAction _ UnInit = Some . Init <$> QC. arbitrary
293298 arbitraryAction _ model@ (Model chain secParam) =
@@ -316,6 +321,7 @@ instance StateModel Model where
316321 )
317322 , (1 , pure $ Some WipeLedgerDB )
318323 , (1 , pure $ Some TruncateSnapshots )
324+ , (1 , pure $ Some OpenAndCloseForker )
319325 ]
320326
321327 initialState = UnInit
@@ -357,6 +363,7 @@ instance StateModel Model where
357363 nextState state WipeLedgerDB _var = state
358364 nextState state TruncateSnapshots _var = state
359365 nextState state (DropAndRestore n) _var = modelRollback n state
366+ nextState state OpenAndCloseForker _var = state
360367 nextState UnInit _ _ = error " Uninitialized model created a command different than Init"
361368
362369 precondition UnInit Init {} = True
@@ -566,6 +573,13 @@ instance RunModel Model (StateT Environment IO) where
566573 atomically $ modifyTVar (dbChain chainDb) (drop (fromIntegral n))
567574 closeLedgerDB testInternals
568575 perform state (Init secParam) lk
576+ perform _ OpenAndCloseForker _ = do
577+ Environment ldb _ _ _ _ _ _ <- get
578+ lift $ withRegistry $ \ rr -> do
579+ eFrk <- LedgerDB. getForkerAtTarget ldb rr VolatileTip
580+ case eFrk of
581+ Left err -> error $ " Impossible: can't acquire forker at tip: " <> show err
582+ Right frk -> forkerClose frk
569583 perform _ TruncateSnapshots _ = do
570584 Environment _ testInternals _ _ _ _ _ <- get
571585 lift $ truncateSnapshots testInternals
0 commit comments