Skip to content

Commit

Permalink
add additional open/close db test
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed May 31, 2019
1 parent 2cf3677 commit 15ed9d9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/core/test/unit/Cardano/Wallet/DB/SqliteCorruptionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ import Data.Text.Class
import Data.Time.Clock
( getCurrentTime )
import Database.Sqlite
( Connection )
( Connection, close )
import System.IO.Unsafe
( unsafePerformIO )
import Test.Hspec
( Expectation, Spec, before, describe, it, shouldReturn )
import Test.QuickCheck
( Property, choose, generate, property )
( Property, choose, generate, property, (==>) )
import Test.QuickCheck.Monadic
( monadicIO )

Expand All @@ -84,6 +84,15 @@ import qualified Data.Set as Set

spec :: Spec
spec = do
describe "Check db opening/closing" $ do
it "opening and closing of db works" $ do
(conn, db) <- fileDBLayer
_ <- cleanDB db
unsafeRunExceptT $ createWallet db testPk testCp testMetadata
listWallets db `shouldReturn` [testPk]
close conn
forM_ [1..25] openCloseDB

before ((snd <$> fileDBLayer) >>= cleanDB) $
describe "Check db reading/writing from/to file and cleaning" $ do

Expand Down Expand Up @@ -159,17 +168,24 @@ spec = do
(_,db2) <- fileDBLayer
call db2 `shouldReturn` expectedAfterClean

openCloseDB :: Int -> IO ()
openCloseDB _ = do
(conn, db) <- fileDBLayer
listWallets db `shouldReturn` [testPk]
close conn


prop_randomOpChunks
:: DBLayer IO (SeqState DummyTarget) DummyTarget
-> KeyValPairs (PrimaryKey WalletId) (Wallet (SeqState DummyTarget) DummyTarget , WalletMetadata)
-> Property
prop_randomOpChunks inMemoryDB (KeyValPairs pairs) =
monadicIO (pure inMemoryDB >>= prop)
L.length pairs > 0 ==> monadicIO (pure inMemoryDB >>= prop)
where
prop dbM = liftIO $ do
(_, dbF) <- fileDBLayer
_ <- cleanDB dbF
_ <- cleanDB inMemoryDB

forM_ pairs (updateDB dbM)
chunks <- cutRandomly [] pairs
Expand Down

0 comments on commit 15ed9d9

Please sign in to comment.