Add test for non-atomic vote persistence in handleRequestVoteRequest#1242
Add test for non-atomic vote persistence in handleRequestVoteRequest#1242Qian-Cheng-nju wants to merge 1 commit intosofastack:masterfrom
Conversation
|
Hi @Qian-Cheng-nju, welcome to SOFAStack community, Please sign Contributor License Agreement! After you signed CLA, we will automatically sync the status of this pull request in 3 minutes. |
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds a new test class that simulates disk I/O failure during vote persistence (setVotedFor) by injecting an instrumented RaftMetaStorage, and includes tests reproducing normal-restart and crash-induced double-vote scenarios within the raft test cluster. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@jraft-core/src/test/java/com/alipay/sofa/jraft/core/VotePersistenceBugTest.java`:
- Around line 235-241: The test VotePersistenceBugTest currently asserts the
buggy double-vote behavior by checking resp2.getGranted() with assertTrue;
update the test to mark this as a known-to-be-broken assertion and flip it to
assertFalse once issue `#1241` (atomic vote persistence) is fixed. Specifically,
locate the block using NodeImpl node2, method
handleRequestVoteRequest(buildVoteRequest(...)) producing resp2, and replace the
assertTrue(resp2.getGranted()) with assertFalse(resp2.getGranted()) or wrap it
with a clear FIXME comment (e.g., "// FIXME: flip to assertFalse after `#1241` is
fixed") so future maintainers know to change the assertion when the bug is
resolved. Ensure the message text referencing candidate1/candidate2 remains
informative after the flip.
🧹 Nitpick comments (3)
jraft-core/src/test/java/com/alipay/sofa/jraft/core/VotePersistenceBugTest.java (3)
47-67: LGTM on class setup and Javadoc.The class-level Javadoc clearly explains the two-phase persistence problem being tested. The
@Beforesetup is consistent with other JRaft tests.Minor: the
testNamerule (line 57-58) is declared but never referenced in either test method. Consider removing it if not needed.,
155-158:getMetaFilePathis unused — consider removing.This helper is defined but never called in either test. It appears to have been superseded by the
CrashPointMetaStorage.metaFilePathapproach for reading on-disk state. Removing it avoids confusion.🧹 Remove unused method
- private String getMetaFilePath(final PeerId peer) { - return this.dataPath + File.separator + peer.getEndpoint().toString().replace(':', '_') + File.separator - + "meta" + File.separator + "raft_meta"; - }
69-78: Teardown robustness: consider adding a try-finally aroundstopAll.If
c.stopAll()throws for one cluster, the remaining clusters inCLUSTERSwon't be stopped, andFileUtils.deleteDirectory/NodeManager.clear()won't execute. A try-finally or try-catch inside the loop would improve test isolation.Wrap cluster shutdown in try-catch
`@After` public void teardown() throws Exception { if (!TestCluster.CLUSTERS.isEmpty()) { for (final TestCluster c : TestCluster.CLUSTERS.removeAll()) { - c.stopAll(); + try { + c.stopAll(); + } catch (final Exception e) { + // log and continue to ensure remaining cleanup executes + } } } - FileUtils.deleteDirectory(new File(this.dataPath)); - NodeManager.getInstance().clear(); + try { + FileUtils.deleteDirectory(new File(this.dataPath)); + } finally { + NodeManager.getInstance().clear(); + } }
jraft-core/src/test/java/com/alipay/sofa/jraft/core/VotePersistenceBugTest.java
Outdated
Show resolved
Hide resolved
dbc4bf3 to
0b9a695
Compare
Reproduction test for the issue described in #1241.
Summary by CodeRabbit