Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nvanbenschoten
Copy link
Contributor

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

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 <nvanbenschoten@gmail.com>
@nvanbenschoten
Copy link
Contributor Author

@pav-kv when you get a chance, want to give this testing PR a pass?

@pav-kv pav-kv self-requested a review February 1, 2024 18:05
Copy link
Contributor

@pav-kv pav-kv left a 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)
Copy link
Contributor

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?

Copy link
Member

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.

Comment on lines +1941 to +1942
// Its self-vote does not make its way to its ProgressTracker.
granted, _, _ := sm.trk.TallyVotes()
Copy link
Contributor

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.

Comment on lines +1821 to +1823
if sm.state != expState {
t.Errorf("state = %v, want %v", sm.state, expState)
}
Copy link
Member

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.

Suggested change
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)
Copy link
Member

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.

Comment on lines +1904 to +1908
// 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)
}
Copy link
Member

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)

Suggested change
// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

@ahrtr
Copy link
Member

ahrtr commented Feb 2, 2024

Overall looks good to me. Just a couple of minor comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants