Skip to content

Commit

Permalink
Make sure we close DBs in Wallet Sqlite Specs
Browse files Browse the repository at this point in the history
Instead of consuming 10s of GB, we the unit tests only consumes 50 MB at
most. Hopefully this will fix the CI unit test timeouts.
  • Loading branch information
Anviking committed Feb 26, 2021
1 parent 92893c4 commit 67f3e6f
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 67f3e6f

Please sign in to comment.