Skip to content

Commit a03670c

Browse files
author
Julian Ospald
committed
Add DB test for last GC time
1 parent f7b4f86 commit a03670c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ instance PersistField POSIXTime where
673673
. formatTime defaultTimeLocale (iso8601DateFormat (Just "%H:%M:%S"))
674674
. posixSecondsToUTCTime
675675
fromPersistValue (PersistText time) =
676-
fmap utcTimeToPOSIXSeconds $
676+
utcTimeToPOSIXSeconds <$>
677677
parseTimeM True defaultTimeLocale
678678
(iso8601DateFormat (Just "%H:%M:%S")) (T.unpack time)
679679
fromPersistValue _ = Left "Could not convert to unknown constructor POSIX seconds"

lib/core/test/unit/Cardano/Pool/DB/Properties.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
{-# LANGUAGE OverloadedLabels #-}
77
{-# LANGUAGE RankNTypes #-}
88
{-# LANGUAGE RecordWildCards #-}
9+
{-# LANGUAGE TypeApplications #-}
910
{-# LANGUAGE TypeFamilies #-}
11+
{-# LANGUAGE TypeSynonymInstances #-}
1012
{-# OPTIONS_GHC -fno-warn-orphans #-}
1113

1214
module Cardano.Pool.DB.Properties
@@ -87,6 +89,8 @@ import Data.Quantity
8789
( Quantity (..) )
8890
import Data.Text.Class
8991
( toText )
92+
import Data.Time.Clock.POSIX
93+
( POSIXTime )
9094
import Data.Word
9195
( Word64 )
9296
import Fmt
@@ -217,6 +221,8 @@ properties = do
217221
(property . prop_putHeaderListHeader)
218222
it "modSettings . readSettings == id"
219223
(property . prop_modSettingsReadSettings)
224+
it "putLastMetadataGC . readLastMetadataGC == id"
225+
(property . prop_putLastMetadataGCReadLastMetadataGC)
220226

221227
{-------------------------------------------------------------------------------
222228
Properties
@@ -1431,6 +1437,24 @@ prop_modSettingsReadSettings DBLayer{..} settings = do
14311437
assertWith "Modifying settings and reading afterwards works"
14321438
(modSettings' == settings)
14331439

1440+
-- | read . put == pure
1441+
prop_putLastMetadataGCReadLastMetadataGC
1442+
:: DBLayer IO
1443+
-> POSIXTime
1444+
-> Property
1445+
prop_putLastMetadataGCReadLastMetadataGC DBLayer{..} posixTime = do
1446+
monadicIO (setup >> prop)
1447+
where
1448+
setup = run $ atomically cleanDB
1449+
prop = do
1450+
defGCTime <- run $ atomically readLastMetadataGC
1451+
assertWith "Reading sync time from empty db returns start of unix epoch"
1452+
(defGCTime == fromIntegral @Int 0)
1453+
run $ atomically $ putLastMetadataGC posixTime
1454+
time <- run $ atomically readLastMetadataGC
1455+
assertWith "Setting sync time and reading afterwards works"
1456+
(time == posixTime)
1457+
14341458
descSlotsPerPool :: Map PoolId [BlockHeader] -> Expectation
14351459
descSlotsPerPool pools = do
14361460
let checkIfDesc slots =
@@ -1484,3 +1508,8 @@ testCertificatePublicationTimes =
14841508

14851509
instance Arbitrary BlockHeader where
14861510
arbitrary = genSlotNo >>= genBlockHeader
1511+
1512+
instance Arbitrary POSIXTime where
1513+
arbitrary = do
1514+
(Positive int) <- arbitrary @(Positive Int)
1515+
pure (fromIntegral int)

0 commit comments

Comments
 (0)