-
Notifications
You must be signed in to change notification settings - Fork 165
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
Improve testing around TestCandidateSelfVoteAfterWonElection #127
base: main
Are you sure you want to change the base?
Improve testing around TestCandidateSelfVoteAfterWonElection #127
Conversation
This commit improves the testing around cases where a (pre-)candidate wins an election without having voted for themselves. This was already tested by TestCandidateDeliversPreCandidateSelfVoteAfterBecomingCandidate, but this commit expands the testing to handle three related cases and to mirror the existing TestCandidateSelfVoteAfterLostElection test. Signed-off-by: Nathan VanBenschoten <[email protected]>
@pav-kv when you get a chance, want to give this testing PR a pass? |
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.
LGTM % a couple of nice-to-haves
expState = StatePreCandidate | ||
} | ||
if sm.state != expState { | ||
t.Errorf("state = %v, want %v", sm.state, expState) |
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.
Convert these to use require
package while here?
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.
+1, pls see my previous comment.
// Its self-vote does not make its way to its ProgressTracker. | ||
granted, _, _ := sm.trk.TallyVotes() |
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? Is this because the leader doesn't count votes in general (it doesn't need to already)? Or there is just special handling of leader self-vote?
Might be good to clarify the comment.
if sm.state != expState { | ||
t.Errorf("state = %v, want %v", sm.state, expState) | ||
} |
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.
This minor comment also applies to all other places.
if sm.state != expState { | |
t.Errorf("state = %v, want %v", sm.state, expState) | |
} | |
require.Equal(t, expState, sm.state) |
expState = StatePreCandidate | ||
} | ||
if sm.state != expState { | ||
t.Errorf("state = %v, want %v", sm.state, expState) |
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.
+1, pls see my previous comment.
// Nothing new should be sent since n1 first learned that it was a | ||
// candidate. | ||
if steps3 := sm.takeMessagesAfterAppend(); len(steps3) != 0 { | ||
t.Errorf("unexpected new messages after pre-vote self-vote: %+v", steps3) | ||
} |
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.
The r.msgsAfterAppend
has already been reset to nil
when getting the steps2
(line 1888)
// Nothing new should be sent since n1 first learned that it was a | |
// candidate. | |
if steps3 := sm.takeMessagesAfterAppend(); len(steps3) != 0 { | |
t.Errorf("unexpected new messages after pre-vote self-vote: %+v", steps3) | |
} |
sm.stepOrSend(steps) | ||
if sm.state != StateLeader { | ||
t.Errorf("state = %v, want %v", sm.state, StateLeader) | ||
} | ||
|
||
// Its self-vote does not make its way to its ProgressTracker. |
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.
// Its self-vote does not make its way to its ProgressTracker. | |
// The delayed self-vote and pre-vote do not make its way to its ProgressTracker. |
Overall looks good to me. Just a couple of minor comments. |
This commit improves the testing around cases where a (pre-)candidate wins an election without having voted for themselves. This was already tested by TestCandidateDeliversPreCandidateSelfVoteAfterBecomingCandidate, but this commit expands the testing to handle three related cases and to mirror the existing TestCandidateSelfVoteAfterLostElection test.
cc. @pav-kv