Skip to content

Commit 74b85d9

Browse files
committed
Test that uncommitted forkers do not leak handles
1 parent 973586b commit 74b85d9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ouroboros-consensus/ouroboros-consensus.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ test-suite storage-test
745745
ouroboros-consensus,
746746
ouroboros-network-api,
747747
ouroboros-network-mock,
748+
ouroboros-network-protocols,
748749
pretty-show,
749750
quickcheck-dynamic,
750751
quickcheck-lockstep ^>=0.8,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import Ouroboros.Consensus.Util hiding (Some)
7575
import Ouroboros.Consensus.Util.Args
7676
import Ouroboros.Consensus.Util.IOLike
7777
import qualified Ouroboros.Network.AnchoredSeq as AS
78+
import Ouroboros.Network.Protocol.LocalStateQuery.Type
7879
import qualified System.Directory as Dir
7980
import System.FS.API
8081
import qualified System.FS.IO as FSIO
@@ -325,6 +326,7 @@ instance StateModel Model where
325326
Action Model (ExtLedgerState TestBlock EmptyMK, ExtLedgerState TestBlock EmptyMK)
326327
Init :: SecurityParam -> LSM.Salt -> Action Model ()
327328
ValidateAndCommit :: Word64 -> [TestBlock] -> Action Model ()
329+
OpenAndCloseForker :: Action Model ()
328330

329331
actionName WipeLedgerDB{} = "WipeLedgerDB"
330332
actionName TruncateSnapshots{} = "TruncateSnapshots"
@@ -333,6 +335,7 @@ instance StateModel Model where
333335
actionName GetState{} = "GetState"
334336
actionName Init{} = "Init"
335337
actionName ValidateAndCommit{} = "ValidateAndCommit"
338+
actionName OpenAndCloseForker = "OpenAndCloseForker"
336339

337340
arbitraryAction _ UnInit = Some <$> (Init <$> QC.arbitrary <*> QC.arbitrary)
338341
arbitraryAction _ model@(Model chain secParam) =
@@ -361,6 +364,7 @@ instance StateModel Model where
361364
)
362365
, (1, pure $ Some WipeLedgerDB)
363366
, (1, pure $ Some TruncateSnapshots)
367+
, (1, pure $ Some OpenAndCloseForker)
364368
]
365369

366370
initialState = UnInit
@@ -402,6 +406,7 @@ instance StateModel Model where
402406
nextState state WipeLedgerDB _var = state
403407
nextState state TruncateSnapshots _var = state
404408
nextState state (DropAndRestore n _) _var = modelRollback n state
409+
nextState state OpenAndCloseForker _var = state
405410
nextState UnInit _ _ = error "Uninitialized model created a command different than Init"
406411

407412
precondition UnInit Init{} = True
@@ -635,6 +640,12 @@ instance RunModel Model (StateT Environment IO) where
635640
atomically $ modifyTVar (dbChain chainDb) (drop (fromIntegral n))
636641
closeLedgerDB testInternals
637642
perform state (Init secParam salt) lk
643+
perform _ OpenAndCloseForker _ = do
644+
Environment ldb _ _ _ _ _ _ rr <- get
645+
eFrk <- lift $ LedgerDB.getForkerAtTarget ldb rr VolatileTip
646+
case eFrk of
647+
Left err -> error $ "Impossible: can't acquire forker at tip: " <> show err
648+
Right frk -> lift $ forkerClose frk
638649
perform _ TruncateSnapshots _ = do
639650
Environment _ testInternals _ _ _ _ _ _ <- get
640651
lift $ truncateSnapshots testInternals

0 commit comments

Comments
 (0)