Skip to content

Commit aa271ff

Browse files
committed
LedgerDB.TestInternals: add getNumLedgerTablesHandles
for testing that we do not leak any, in a follow-up commit
1 parent 55d84c3 commit aa271ff

File tree

4 files changed

+9
-1
lines changed
  • ouroboros-consensus

4 files changed

+9
-1
lines changed

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/API.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ data TestInternals m l blk = TestInternals
302302
, reapplyThenPushNOW :: blk -> m ()
303303
, truncateSnapshots :: m ()
304304
, closeLedgerDB :: m ()
305+
, getNumLedgerTablesHandles :: m Word64
306+
-- ^ Get the number of referenced 'LedgerTablesHandle's for V2. For V1, this
307+
-- always returns 0.
305308
}
306309
deriving NoThunks via OnlyCheckWhnfNamed "TestInternals" (TestInternals m l blk)
307310

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V1.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ mkInternals h =
353353
, wipeLedgerDB = getEnv h $ void . destroySnapshots . snapshotsFs . ldbHasFS
354354
, closeLedgerDB = getEnv h $ bsClose . ldbBackingStore
355355
, truncateSnapshots = getEnv h $ void . implIntTruncateSnapshots . ldbHasFS
356+
, getNumLedgerTablesHandles = pure 0
356357
}
357358

358359
-- | Testing only! Truncate all snapshots in the DB.

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/LedgerDB/V2.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ mkInternals bss h =
231231
let LDBHandle tvar = h
232232
in atomically (writeTVar tvar LedgerDBClosed)
233233
, truncateSnapshots = getEnv h $ implIntTruncateSnapshots . ldbHasFS
234+
, getNumLedgerTablesHandles = getEnv h $ \env -> do
235+
l <- readTVarIO (ldbSeq env)
236+
-- We always have a state at the anchor.
237+
pure $ 1 + maxRollback l
234238
}
235239
where
236240
takeSnapshot ::

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ initialEnvironment fsOps getLmdbDir mkTestArguments cdb = do
132132
pure $
133133
Environment
134134
undefined
135-
(TestInternals undefined undefined undefined undefined undefined (pure ()))
135+
(TestInternals undefined undefined undefined undefined undefined (pure ()) (pure 0))
136136
cdb
137137
(flip mkTestArguments lmdbDir)
138138
sfs

0 commit comments

Comments
 (0)