Skip to content

Fix flaky StabilityTest.recordAndResetPeerListTest restart and port collision - #19378

Merged
JackieTien97 merged 1 commit into
masterfrom
ty/fix-stability-test-restart-port
Nov 24, 2026
Merged

JackieTien97 merged 1 commit into
masterfrom
ty/fix-stability-test-restart-port

Conversation

@JackieTien97

Copy link
Copy Markdown
Contributor

Bug Scenario

Running StabilityTest.recordAndResetPeerListTest under parallel Surefire forks (e.g. -DforkCount=4) or rapid back-to-back stop() / start() cycles can fail with RejectedExecutionException at IoTConsensus.start():

  1. StabilityTest hardcoded basePort = 6667, so concurrent forks or a rapid stop() -> start() before ThriftService finishes closing its server socket can trigger BindException: Address already in use wrapped in IOException(StartupException).
  2. recordAndResetPeerListTest() called consensusImpl.stop() (which permanently shuts down backgroundTaskService, clientManager, and syncClientManager) and then called consensusImpl.start() on the same stopped IoTConsensus instance, unlike peerTest() and IoTConsensusRecoveryTest, which construct a fresh IoTConsensus instance before restarting.
  3. Previously, stop() left updateReaderFuture non-null, so reusing the stopped instance accidentally skipped rescheduling on the terminated backgroundTaskService. After Stabilize IoTConsensus peer recovery notifications #19348 (45cb9959f1) added cleanupAfterFailedStart(), a BindException during start() clears updateReaderFuture = null; because recordAndResetPeerListTest() caught and swallowed StartupException and continued to the next consensusImpl.start() on the same stopped instance, if (updateReaderFuture == null) became true and threw RejectedExecutionException on the terminated backgroundTaskService.

Before vs. After

  • Before: recordAndResetPeerListTest() bound hardcoded port 6667, restarted a stopped IoTConsensus instance, swallowed StartupException (silently skipping assertions on bind collisions), and failed with RejectedExecutionException on the subsequent restart attempt.
  • After: StabilityTest binds ephemeral port 0 (basePort = 0), constructs a fresh IoTConsensus instance via createConsensus() before each restart in recordAndResetPeerListTest(), guards tearDown() against a null consensusImpl, and removes the StartupException-swallowing try/catch blocks 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:
    • Switch basePort from 6667 to 0 (matching IoTConsensusRecoveryTest).
    • Extract createConsensus() and instantiate a fresh IoTConsensus before each restart in recordAndResetPeerListTest().
    • Remove the StartupException-swallowing try/catch blocks and unused imports/logger.
    • Null-check and clear consensusImpl in tearDown() and after explicit stop() calls.

Verification

  • mvn spotless:apply -pl iotdb-core/consensus (0 violations, checkstyle 0 violations)
  • 5 consecutive runs of mvn test -pl iotdb-core/consensus -am -Dsurefire.failIfNoSpecifiedTests=false -Dtest=StabilityTest -Dsurefire.rerunFailingTestsCount=0 (all passed: 3/3 tests each)
  • Full consensus suite with parallel forks: 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)
  • Chinese locale compile check: mvn test-compile -pl iotdb-core/consensus -am -P with-zh-locale -DskipTests (passed)

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.60%. Comparing base (44c228a) to head (7f4759d).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JackieTien97
JackieTien97 merged commit 7ae8c7c into master Nov 24, 2026
40 checks passed
@JackieTien97
JackieTien97 deleted the ty/fix-stability-test-restart-port branch November 24, 2026 06:20
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