Skip to content

Commit

Permalink
Add DB test for last GC time
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Ospald committed Oct 17, 2020
1 parent 5df8706 commit b42eb40
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ instance PersistField POSIXTime where
. formatTime defaultTimeLocale (iso8601DateFormat (Just "%H:%M:%S"))
. posixSecondsToUTCTime
fromPersistValue (PersistText time) =
fmap utcTimeToPOSIXSeconds $
utcTimeToPOSIXSeconds <$>
parseTimeM True defaultTimeLocale
(iso8601DateFormat (Just "%H:%M:%S")) (T.unpack time)
fromPersistValue _ = Left "Could not convert to unknown constructor POSIX seconds"
Expand Down
29 changes: 29 additions & 0 deletions lib/core/test/unit/Cardano/Pool/DB/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Cardano.Pool.DB.Properties
Expand Down Expand Up @@ -87,6 +89,8 @@ import Data.Quantity
( Quantity (..) )
import Data.Text.Class
( toText )
import Data.Time.Clock.POSIX
( POSIXTime )
import Data.Word
( Word64 )
import Fmt
Expand Down Expand Up @@ -217,6 +221,8 @@ properties = do
(property . prop_putHeaderListHeader)
it "modSettings . readSettings == id"
(property . prop_modSettingsReadSettings)
it "putLastMetadataGC . readLastMetadataGC == id"
(property . prop_putLastMetadataGCReadLastMetadataGC)

{-------------------------------------------------------------------------------
Properties
Expand Down Expand Up @@ -1431,6 +1437,24 @@ prop_modSettingsReadSettings DBLayer{..} settings = do
assertWith "Modifying settings and reading afterwards works"
(modSettings' == settings)

-- | read . put == pure
prop_putLastMetadataGCReadLastMetadataGC
:: DBLayer IO
-> POSIXTime
-> Property
prop_putLastMetadataGCReadLastMetadataGC DBLayer{..} posixTime = do
monadicIO (setup >> prop)
where
setup = run $ atomically cleanDB
prop = do
defGCTime <- run $ atomically readLastMetadataGC
assertWith "Reading sync time from empty db returns start of unix epoch"
(defGCTime == fromIntegral @Int 0)
run $ atomically $ putLastMetadataGC posixTime
time <- run $ atomically readLastMetadataGC
assertWith "Setting sync time and reading afterwards works"
(time == posixTime)

descSlotsPerPool :: Map PoolId [BlockHeader] -> Expectation
descSlotsPerPool pools = do
let checkIfDesc slots =
Expand Down Expand Up @@ -1484,3 +1508,8 @@ testCertificatePublicationTimes =

instance Arbitrary BlockHeader where
arbitrary = genSlotNo >>= genBlockHeader

instance Arbitrary POSIXTime where
arbitrary = do
(Positive int) <- arbitrary @(Positive Int)
pure (fromIntegral int)

0 comments on commit b42eb40

Please sign in to comment.