Skip to content

Commit

Permalink
Merge #2537
Browse files Browse the repository at this point in the history
2537: Fix massive memory leak in unit tests r=Anviking a=Anviking

# Issue Number

ADP-758, #2472 

# Overview

- [x] Make sure to also close the DBLayers we create!
- [x] <s>Use validateGenerator to also test non-QSM Arbitrary instances</s>
- [ ] <s>TODO: Look a bit more at the generators / validation of them, could perhaps split the PR too.</s>

# Comments

Before this fix the memory usage would steadily climb upwards 5-15GB. Now it's at most ~40 MB.

### Running part of unit tests before fix:
<img width="1167" alt="ska__rmavbild_2021-02-25_kl _12 34 43" src="https://user-images.githubusercontent.com/304423/109172195-cafd8c00-7782-11eb-8afd-a40732fccded.png">


### Running all unit tests after fix:
<img width="1399" alt="Skärmavbild 2021-02-25 kl  15 54 16" src="https://user-images.githubusercontent.com/304423/109171975-938edf80-7782-11eb-904b-9404708fbdde.png">


<!-- Additional comments or screenshots to attach if any -->

<!--
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Jira will detect and link to this PR once created, but you can also link this PR in the description of the corresponding ticket
 ✓ Acknowledge any changes required to the Wiki
 ✓ Finally, in the PR description delete any empty sections and all text commented in <!--, so that this text does not appear in merge commit messages.
-->


Co-authored-by: Johannes Lund <[email protected]>
  • Loading branch information
iohk-bors[bot] and Anviking authored Feb 26, 2021
2 parents 5c6542c + 67f3e6f commit e45ff29
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 136 deletions.
27 changes: 9 additions & 18 deletions lib/core/test/unit/Cardano/Pool/DB/SqliteSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,42 @@ module Cardano.Pool.DB.SqliteSpec
import Prelude

import Cardano.BM.Trace
( traceInTVarIO )
( nullTracer )
import Cardano.DB.Sqlite
( DBLog (..), SqliteContext )
( DBLog (..) )
import Cardano.Pool.DB
( DBLayer (..) )
import Cardano.Pool.DB.Log
( PoolDbLog (..) )
import Cardano.Pool.DB.Properties
( properties )
import Cardano.Pool.DB.Sqlite
( newDBLayer, withDBLayer )
( withDBLayer )
import Cardano.Wallet.DummyTarget.Primitive.Types
( dummyTimeInterpreter )
import System.Directory
( copyFile )
import System.FilePath
( (</>) )
import Test.Hspec
( Spec, before, describe, it, shouldBe )
( Spec, around, describe, it, shouldBe )
import Test.Hspec.Extra
( parallel )
import Test.Utils.Paths
( getTestData )
import Test.Utils.Trace
( captureLogging )
import UnliftIO.STM
( TVar, newTVarIO )
import UnliftIO.Temporary
( withSystemTempDirectory )

-- | Set up a DBLayer for testing, with the command context, and the logging
-- variable.
newMemoryDBLayer :: IO (DBLayer IO)
newMemoryDBLayer = snd . snd <$> newMemoryDBLayer'

newMemoryDBLayer' :: IO (TVar [PoolDbLog], (SqliteContext, DBLayer IO))
newMemoryDBLayer' = do
logVar <- newTVarIO []
(logVar, ) <$> newDBLayer (traceInTVarIO logVar) Nothing ti
where
ti = dummyTimeInterpreter
withMemoryDBLayer
:: (DBLayer IO -> IO a)
-> IO a
withMemoryDBLayer = withDBLayer nullTracer Nothing dummyTimeInterpreter

spec :: Spec
spec = parallel $ do
before newMemoryDBLayer $ do
around withMemoryDBLayer $ do
parallel $ describe "Sqlite" properties

describe "Migration Regressions" $ do
Expand Down
Loading

0 comments on commit e45ff29

Please sign in to comment.