Skip to content

Wait for the elections the server tests expect - #15

Merged
chrislusf merged 1 commit into
masterfrom
fix/server-test-timing
Jul 30, 2026
Merged

Wait for the elections the server tests expect#15
chrislusf merged 1 commit into
masterfrom
fix/server-test-timing

Conversation

@chrislusf

Copy link
Copy Markdown
Collaborator

CI on master is red on TestServerPromoteSelf:

server_test.go:199: Server self-promotion failed: candidate

The test starts a single server and sleeps 2 * testElectionTimeout before requiring it to be leader:

s.Start()
time.Sleep(2 * testElectionTimeout)

if s.State() != Leader {
    t.Fatalf("Server self-promotion failed: %v", s.State())
}

The server runs with the default election timeout, and a follower waits a randomised interval between one and two of those before putting itself forward — up to 300ms — against a 400ms sleep. Add scheduling delay on a loaded runner and the sleep expires with the server still a candidate.

TestServerRecoverFromPreviousLogAndConf has the same shape twice, and it has taken CI red on two branches recently. It fails in both directions: too early and a server has not caught up ([6/17]), too late and a second election has added another no-op and carried it past the number the test names ([18/16]).

Fix

Wait for the state each phase expects instead of for an interval that looks long enough.

The commit index is treated as a floor rather than an exact value. Requiring exactly 16 or 17 pins how many elections the run happened to hold, which is not what either test is checking — extra no-ops are a leader doing its job. Under-commit is still caught, by the deadline.

Two things this turned up that are worth stating, because the first version of the fix had both:

  • the waits have to finish for every server before any of them is stopped. Polling and stopping in the same pass stops the leader as soon as it is caught up, and the followers then have nothing to catch up from. That fails reliably under -count=5, where the original sleep-then-check does not.
  • polling for exact equality is worse than the sleep it replaces: given longer to look, the cluster elects again and overshoots.

Verification

TestServerPromoteSelf and TestServerRecoverFromPreviousLogAndConf at -count=3, ten times over: no failures. Full suite clean three times.

TestServerPromoteSelf sleeps twice the election timeout and then requires
the server to already be leader. The wait before a follower puts itself
forward is randomised between one and two election timeouts, so on a busy
machine the sleep can expire first and the server reads back as a
candidate. It failed CI on master this way.

TestServerRecoverFromPreviousLogAndConf has the same shape twice, and
fails in both directions: too early and a server has not caught up, too
late and a second election has added another no-op and taken it past the
number the test names.

Wait for the commit index to reach what each phase expects rather than
for an interval that looks long enough, and treat it as a floor. Pinning
it exactly pins how many elections the run happened to hold, which is not
what either test is about. The servers are all caught up before any of
them is stopped, since stopping the leader first leaves the rest with
nothing to catch up from.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

chrislusf has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@chrislusf, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ac1c3f09-d4a8-45f4-88e6-5aea0e28f8ab

📥 Commits

Reviewing files that changed from the base of the PR and between 080430a and 52f7563.

📒 Files selected for processing (1)
  • server_test.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chrislusf
chrislusf merged commit 59a6664 into master Jul 30, 2026
2 checks passed
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.

1 participant