Repository navigation
Fix flaky StabilityTest.recordAndResetPeerListTest restart and port collision - #19378
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19378 +/- ##
=========================================
Coverage 49.60% 49.60%
Complexity 718 718
=========================================
Files 5671 5671
Lines 419616 419616
Branches 55507 55507
=========================================
+ Hits 208131 208142 +11
+ Misses 211485 211474 -11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Scenario
Running
StabilityTest.recordAndResetPeerListTestunder parallel Surefire forks (e.g.-DforkCount=4) or rapid back-to-backstop()/start()cycles can fail withRejectedExecutionExceptionatIoTConsensus.start():StabilityTesthardcodedbasePort = 6667, so concurrent forks or a rapidstop()->start()beforeThriftServicefinishes closing its server socket can triggerBindException: Address already in usewrapped inIOException(StartupException).recordAndResetPeerListTest()calledconsensusImpl.stop()(which permanently shuts downbackgroundTaskService,clientManager, andsyncClientManager) and then calledconsensusImpl.start()on the same stoppedIoTConsensusinstance, unlikepeerTest()andIoTConsensusRecoveryTest, which construct a freshIoTConsensusinstance before restarting.stop()leftupdateReaderFuturenon-null, so reusing the stopped instance accidentally skipped rescheduling on the terminatedbackgroundTaskService. After Stabilize IoTConsensus peer recovery notifications #19348 (45cb9959f1) addedcleanupAfterFailedStart(), aBindExceptionduringstart()clearsupdateReaderFuture = null; becauserecordAndResetPeerListTest()caught and swallowedStartupExceptionand continued to the nextconsensusImpl.start()on the same stopped instance,if (updateReaderFuture == null)becametrueand threwRejectedExecutionExceptionon the terminatedbackgroundTaskService.Before vs. After
recordAndResetPeerListTest()bound hardcoded port6667, restarted a stoppedIoTConsensusinstance, swallowedStartupException(silently skipping assertions on bind collisions), and failed withRejectedExecutionExceptionon the subsequent restart attempt.StabilityTestbinds ephemeral port0(basePort = 0), constructs a freshIoTConsensusinstance viacreateConsensus()before each restart inrecordAndResetPeerListTest(), guardstearDown()against anullconsensusImpl, and removes theStartupException-swallowingtry/catchblocks so all three assertions (size == 2,size == 1,getImpl == null) are always strictly enforced.Changes
iotdb-core/consensus/src/test/java/org/apache/iotdb/consensus/iot/StabilityTest.java:basePortfrom6667to0(matchingIoTConsensusRecoveryTest).createConsensus()and instantiate a freshIoTConsensusbefore each restart inrecordAndResetPeerListTest().StartupException-swallowingtry/catchblocks and unused imports/logger.consensusImplintearDown()and after explicitstop()calls.Verification
mvn spotless:apply -pl iotdb-core/consensus(0 violations, checkstyle 0 violations)mvn test -pl iotdb-core/consensus -am -Dsurefire.failIfNoSpecifiedTests=false -Dtest=StabilityTest -Dsurefire.rerunFailingTestsCount=0(all passed: 3/3 tests each)mvn test -pl iotdb-core/consensus -am -Dsurefire.failIfNoSpecifiedTests=false -DforkCount=4 -Dtest="org.apache.iotdb.consensus.**.*Test" -Dsurefire.rerunFailingTestsCount=0(109/109 tests passed, 0 skipped)mvn test-compile -pl iotdb-core/consensus -am -P with-zh-locale -DskipTests(passed)