@@ -72,6 +72,7 @@ import Ouroboros.Consensus.Util hiding (Some)
72
72
import Ouroboros.Consensus.Util.Args
73
73
import Ouroboros.Consensus.Util.IOLike
74
74
import qualified Ouroboros.Network.AnchoredSeq as AS
75
+ import Ouroboros.Network.Protocol.LocalStateQuery.Type
75
76
import qualified System.Directory as Dir
76
77
import System.FS.API
77
78
import qualified System.FS.IO as FSIO
@@ -280,6 +281,9 @@ instance StateModel Model where
280
281
Action Model (ExtLedgerState TestBlock EmptyMK , ExtLedgerState TestBlock EmptyMK )
281
282
Init :: SecurityParam -> Action Model ()
282
283
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 ()
283
287
284
288
actionName WipeLedgerDB {} = " WipeLedgerDB"
285
289
actionName TruncateSnapshots {} = " TruncateSnapshots"
@@ -288,6 +292,7 @@ instance StateModel Model where
288
292
actionName GetState {} = " GetState"
289
293
actionName Init {} = " Init"
290
294
actionName ValidateAndCommit {} = " ValidateAndCommit"
295
+ actionName OpenAndCloseForker = " OpenAndCloseForker"
291
296
292
297
arbitraryAction _ UnInit = Some . Init <$> QC. arbitrary
293
298
arbitraryAction _ model@ (Model chain secParam) =
@@ -316,6 +321,7 @@ instance StateModel Model where
316
321
)
317
322
, (1 , pure $ Some WipeLedgerDB )
318
323
, (1 , pure $ Some TruncateSnapshots )
324
+ , (1 , pure $ Some OpenAndCloseForker )
319
325
]
320
326
321
327
initialState = UnInit
@@ -357,6 +363,7 @@ instance StateModel Model where
357
363
nextState state WipeLedgerDB _var = state
358
364
nextState state TruncateSnapshots _var = state
359
365
nextState state (DropAndRestore n) _var = modelRollback n state
366
+ nextState state OpenAndCloseForker _var = state
360
367
nextState UnInit _ _ = error " Uninitialized model created a command different than Init"
361
368
362
369
precondition UnInit Init {} = True
@@ -566,6 +573,13 @@ instance RunModel Model (StateT Environment IO) where
566
573
atomically $ modifyTVar (dbChain chainDb) (drop (fromIntegral n))
567
574
closeLedgerDB testInternals
568
575
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
569
583
perform _ TruncateSnapshots _ = do
570
584
Environment _ testInternals _ _ _ _ _ <- get
571
585
lift $ truncateSnapshots testInternals
0 commit comments