@@ -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) =
@@ -322,6 +327,7 @@ instance StateModel Model where
322
327
)
323
328
, (1 , pure $ Some WipeLedgerDB )
324
329
, (1 , pure $ Some TruncateSnapshots )
330
+ , (1 , pure $ Some OpenAndCloseForker )
325
331
]
326
332
327
333
initialState = UnInit
@@ -363,6 +369,7 @@ instance StateModel Model where
363
369
nextState state WipeLedgerDB _var = state
364
370
nextState state TruncateSnapshots _var = state
365
371
nextState state (DropAndRestore n) _var = modelRollback n state
372
+ nextState state OpenAndCloseForker _var = state
366
373
nextState UnInit _ _ = error " Uninitialized model created a command different than Init"
367
374
368
375
precondition UnInit Init {} = True
@@ -583,6 +590,14 @@ instance RunModel Model (StateT Environment IO) where
583
590
atomically $ modifyTVar (dbChain chainDb) (drop (fromIntegral n))
584
591
closeLedgerDB testInternals
585
592
perform state (Init secParam) lk
593
+ perform _ OpenAndCloseForker _ = do
594
+ Environment ldb _ _ _ _ _ _ <- get
595
+ lift $ withRegistry $ \ rr -> do
596
+ eFrk <- LedgerDB. getForkerAtTarget ldb rr VolatileTip
597
+ case eFrk of
598
+ Left err -> error $ " Impossible: can't acquire forker at tip: " <> show err
599
+ Right frk -> forkerClose frk
600
+ pure $ pure ()
586
601
perform _ TruncateSnapshots _ = do
587
602
Environment _ testInternals _ _ _ _ _ <- get
588
603
lift $ truncateSnapshots testInternals
0 commit comments