• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

databendlabs / openraft / 24138121229

08 Apr 2026 12:45PM UTC coverage: 90.438% (+0.3%) from 90.122%
24138121229

push

github

drmingdrmer
Fix: prevent redundant election when single voter is already electing

When a single-voter node calls `elect()` during `initialize()`, it
becomes a Candidate with an uncommitted vote. Before the vote flush
completes, an election tick can fire and trigger a second `elect()`,
bumping the term unnecessarily (e.g., T1 → T2). This caused flaky
test failures in `single-term-leader` mode where `new_cluster()`
expected `vote == <T1-N0:Q>` but observed `<T2-N0:Q>`.

The fix checks `candidate_ref().is_some()` to detect an in-progress
election. This is precise because the `Candidate` struct only exists
between an `elect()` call and becoming Leader — it is never present
after a node restart, unlike vote-based checks (`is_leading()`) which
would incorrectly match persisted votes from a previous run.

2 of 4 new or added lines in 1 file covered. (50.0%)

13 existing lines in 4 files now uncovered.

9676 of 10699 relevant lines covered (90.44%)

7944.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.8
/openraft/src/error.rs


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc