Skip to content

Commit d61fa19

Browse files
committed
Test that uncommitted forkers do not leak handles
1 parent f3e4dac commit d61fa19

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

ouroboros-consensus/ouroboros-consensus.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ test-suite storage-test
742742
ouroboros-consensus,
743743
ouroboros-network-api,
744744
ouroboros-network-mock,
745+
ouroboros-network-protocols,
745746
pretty-show,
746747
quickcheck-dynamic,
747748
quickcheck-lockstep ^>=0.8,

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import Ouroboros.Consensus.Util hiding (Some)
7272
import Ouroboros.Consensus.Util.Args
7373
import Ouroboros.Consensus.Util.IOLike
7474
import qualified Ouroboros.Network.AnchoredSeq as AS
75+
import Ouroboros.Network.Protocol.LocalStateQuery.Type
7576
import qualified System.Directory as Dir
7677
import System.FS.API
7778
import 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

Comments
 (0)