-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional check for not-leader slots in LeadershipSchedule tests #5110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
module Testnet.Util.Assert | ||
( readJsonLines | ||
, assertChainExtended | ||
, getRelevantLeaderSlots | ||
, getRelevantSlots | ||
) where | ||
|
||
import Prelude hiding (lines) | ||
|
@@ -71,30 +71,44 @@ newtype Kind = Kind | |
{ kind :: Text | ||
} deriving (Eq, Show) | ||
|
||
data TraceNodeIsLeader = TraceNodeIsLeader | ||
{ kind :: Text | ||
, slot :: Int | ||
} deriving (Eq, Show) | ||
|
||
instance FromJSON TraceNodeIsLeader where | ||
parseJSON = Aeson.withObject "TraceNodeIsLeader" $ \v -> do | ||
k <- v .: "val" >>= (.: "kind") | ||
if k == "TraceNodeIsLeader" | ||
then TraceNodeIsLeader k <$> (v .: "val" >>= (.: "slot")) | ||
else fail $ "Expected kind was TraceNodeIsLeader, found " <> show k <> "instead" | ||
data TraceNode | ||
= TraceNode | ||
{ isLeader :: !Bool | ||
, kind :: !Text | ||
, slot :: !Int | ||
} | ||
deriving (Eq, Show) | ||
|
||
instance FromJSON TraceNode where | ||
parseJSON = Aeson.withObject "TraceNode" $ \v -> do | ||
kind' <- v .: "val" >>= (.: "kind") | ||
let slotP = v .: "val" >>= (.: "slot") | ||
case kind' of | ||
"TraceNodeIsLeader" -> TraceNode True kind' <$> slotP | ||
"TraceNodeNotLeader" -> TraceNode False kind' <$> slotP | ||
_ -> fail $ "Expected kind was TraceNodeIsLeader, found " <> show kind' <> "instead" | ||
|
||
instance FromJSON Kind where | ||
parseJSON = Aeson.withObject "Kind" $ \v -> | ||
Kind <$> v .: "kind" | ||
|
||
getRelevantLeaderSlots :: FilePath -> Int -> H.PropertyT (ReaderT IntegrationState (ResourceT IO)) [Int] | ||
getRelevantLeaderSlots poolNodeStdoutFile slotLowerBound = do | ||
getRelevantSlots :: FilePath -> Int -> H.PropertyT (ReaderT IntegrationState (ResourceT IO)) ([Int], [Int]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning something like |
||
getRelevantSlots poolNodeStdoutFile slotLowerBound = do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function now returns all slots seen in the logs. This is useful to double check if we didn't omit any slot, especially those with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also |
||
vs <- readJsonLines poolNodeStdoutFile | ||
let slots = L.map unLogEntry $ Maybe.mapMaybe (Aeson.parseMaybe Aeson.parseJSON) vs | ||
|
||
leaderSlots <- H.noteShow | ||
$ L.map (slot . unLogEntry) | ||
$ Maybe.mapMaybe (Aeson.parseMaybe (Aeson.parseJSON @(LogEntry TraceNodeIsLeader))) | ||
vs | ||
$ map slot | ||
$ filter isLeader slots | ||
notLeaderSlots <- H.noteShow | ||
$ map slot | ||
$ filter (not . isLeader) slots | ||
|
||
relevantLeaderSlots <- H.noteShow | ||
$ L.filter (>= slotLowerBound) | ||
leaderSlots | ||
return relevantLeaderSlots | ||
relevantNotLeaderSlots <- H.noteShow | ||
$ L.filter (>= slotLowerBound) | ||
notLeaderSlots | ||
|
||
pure (relevantLeaderSlots, relevantNotLeaderSlots) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the rename?
TraceNodeIsLeader
was a good name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed a type which would also capture
TraceNodeNotLeader
. So my options were:ToJSON
instanceTraceNodeIsLeader
andTraceNodeNotLeader
, both with fieldsslot
andkind
isLeader
flag3rd looked like the least amount of duplication. Which alternative would you propose?