|
6 | 6 | {-# LANGUAGE OverloadedLabels #-} |
7 | 7 | {-# LANGUAGE RankNTypes #-} |
8 | 8 | {-# LANGUAGE RecordWildCards #-} |
| 9 | +{-# LANGUAGE TypeApplications #-} |
9 | 10 | {-# LANGUAGE TypeFamilies #-} |
| 11 | +{-# LANGUAGE TypeSynonymInstances #-} |
10 | 12 | {-# OPTIONS_GHC -fno-warn-orphans #-} |
11 | 13 |
|
12 | 14 | module Cardano.Pool.DB.Properties |
@@ -87,6 +89,8 @@ import Data.Quantity |
87 | 89 | ( Quantity (..) ) |
88 | 90 | import Data.Text.Class |
89 | 91 | ( toText ) |
| 92 | +import Data.Time.Clock.POSIX |
| 93 | + ( POSIXTime ) |
90 | 94 | import Data.Word |
91 | 95 | ( Word64 ) |
92 | 96 | import Fmt |
@@ -217,6 +221,8 @@ properties = do |
217 | 221 | (property . prop_putHeaderListHeader) |
218 | 222 | it "modSettings . readSettings == id" |
219 | 223 | (property . prop_modSettingsReadSettings) |
| 224 | + it "putLastMetadataGC . readLastMetadataGC == id" |
| 225 | + (property . prop_putLastMetadataGCReadLastMetadataGC) |
220 | 226 |
|
221 | 227 | {------------------------------------------------------------------------------- |
222 | 228 | Properties |
@@ -1431,6 +1437,24 @@ prop_modSettingsReadSettings DBLayer{..} settings = do |
1431 | 1437 | assertWith "Modifying settings and reading afterwards works" |
1432 | 1438 | (modSettings' == settings) |
1433 | 1439 |
|
| 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 | + |
1434 | 1458 | descSlotsPerPool :: Map PoolId [BlockHeader] -> Expectation |
1435 | 1459 | descSlotsPerPool pools = do |
1436 | 1460 | let checkIfDesc slots = |
@@ -1484,3 +1508,8 @@ testCertificatePublicationTimes = |
1484 | 1508 |
|
1485 | 1509 | instance Arbitrary BlockHeader where |
1486 | 1510 | 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