Repository navigation
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
Good job, and thanks a lot for continuing the port-isolation work from #11630, @JeremyXin! Hardcoded Hazelcast ports are one of the most common sources of "passes locally, flaky in CI" failures in the engine E2E module, so every test you move off them helps. I read the full diff against dev and compared it with the helper that #11630 introduced; details below.
What Problem Does This PR Solve?
User pain point: WorkerTagClusterTest (hardcoded start port 5801) and RecordSerializerIT (hardcoded 5901) build their Hazelcast YAML with a fixed starting port. When test JVMs or other clusters run concurrently on the same CI host, they race for the same port range and members fail to start or join the wrong cluster.
Fix approach: Add TestUtils.getAvailablePort(int portCount) to the engine-e2e module (a random start port in 10000-30000, with the whole range probed for bindability and de-duplicated within the JVM), and make both tests allocate one 100-port range per test cluster and give every member of that cluster the same starting port.
One-sentence summary: Give each of these two test clusters its own free, non-overlapping Hazelcast port range instead of a hardcoded one.
Before / after example:
- Before: both tests always start probing at
5801/5901, so any concurrent cluster on that range collides. - After: e.g.
WorkerTagClusterTestpicks17342, and master and worker both useport: 17342, auto-increment: true, port-count: 100, so they still find each other throughtcp-ip: member-list: localhost.
1. Code Change Review
1.1 Core Logic Analysis
This is test-only code (E2E module connector-seatunnel-e2e-base), so there is no production runtime effect. Test path: WorkerTagClusterTest.before() (WorkerTagClusterTest.java:50-56) and RecordSerializerIT.setUp() (RecordSerializerIT.java:58-62) call TestUtils.getAvailablePort(100) once, then build the YAML for both members from that single value.
Before / after:
RecordSerializerIT.java:createHazelcastInstance(clusterName)becomescreateHazelcastInstance(clusterName, hazelcastPort), andbuildHazelcastConfigwritesport: <hazelcastPort>instead of5901.WorkerTagClusterTest.java:getSeaTunnelConfig(testClusterName)andgetHazelcastConfig()take the port, replacing the literal5801.TestUtils.java:41-77: newALLOCATED_PORT_RANGESregistry,getAvailablePort(int), andisAvailablePortRange(int, int).
Key Findings:
- Using the same start port for all members of one cluster is the right call. The tests configure
tcp-ipjoin withmember-list: localhost, so each member probesport .. port + hazelcast.tcp.join.port.try.count (30)on localhost; with a shared start port the first member bindsport, the second auto-increments toport + 1, and they discover each other. A different random port per member would break the join. - The allocator is a faithful port of the helper added in #11630 (
seatunnel-engine-server/.../server/TestUtils.java,getAvailablePort(int portCount)), including the 10000-30000 window chosen to stay out of the OS ephemeral range. I diffed the logic and found no behavioural drift beyond dropping an internal bounds re-check that the random generator already guarantees (nextInt(MIN, MAX - portCount + 2)keepsrangeEnd <= MAX). getHazelcastConfigisprotected staticand its signature changed; a repo-wide search in the engine-e2e module shows no other caller, so nothing else breaks.- Scope: other classes in this module still hardcode
5801, see Issue 1.
In-depth correctness: the registry check plus bind probe makes overlap within one JVM impossible and cross-JVM collisions unlikely; the remaining window is the time between the probe (sockets closed) and Hazelcast actually binding, which is inherent to any probe-then-use scheme and acceptable for tests.
1.2 Compatibility Impact
Fully compatible: test code only, no production class, option, or resource file changes.
1.3 Performance / Side-Effect Analysis
Each allocation tries to bind up to 100 sockets, so about 100 syscalls per attempt; negligible next to starting a Hazelcast instance. One side effect is that ALLOCATED_PORT_RANGES is never released (see Issue 2), which is harmless at current usage.
1.4 Error Handling and Logging
getAvailablePort throws IllegalArgumentException on a bad count and IllegalStateException("Failed to allocate an available port range") after 1000 attempts; both messages are clear enough for test code. Formal issues (all non-blocking):
Issue 1: Other engine-e2e tests still hardcode port: 5801
- Location:
ClusterFaultToleranceIT.java:779,ClusterFaultToleranceIT.java:990,SplitClusterFaultToleranceIT.java:1305; also the sharedsrc/test/resources/hazelcast.yaml:36,cluster/hazelcast.yaml:37,master-worker-cluster/hazelcast-master.yaml:37,job-log-multiport/hazelcast.yaml:37 - Problem: The PR title says "additional E2E tests", but the same hardcoded-port pattern remains in these classes. Some of the YAML resources may be intentionally fixed (for example server1/2/3 use
5801/5802/5803for Docker or multi-process layouts), so I am not asking to change all of them. - Potential risk: The class of flakiness the PR targets can still occur in the remaining in-JVM tests.
- Best improvement: Say explicitly in the PR description that this is a partial follow-up and which classes are deliberately left, or convert the in-JVM string-built configs (
ClusterFaultToleranceIT,SplitClusterFaultToleranceIT) the same way in this PR or a tracked follow-up. - Severity: Low
- Raised by another reviewer: No
Issue 2: Allocated port ranges are never released
- Location:
TestUtils.java:41,:52 - Problem:
ALLOCATED_PORT_RANGESonly grows.WorkerTagClusterTestallocates a fresh 100-port range in every@BeforeEach(4 tests), so a JVM that runs many such tests slowly consumes the 20000-port window (about 200 ranges) and then fails withIllegalStateException. - Potential risk: Not reachable at current test counts, but it is a latent trap if more classes adopt the helper in one JVM.
- Best improvement: Optional: add a
releasePortRange(int port)called from@AfterEach/@AfterAll, or document the limit in a comment. The same limitation exists in the #11630 helper, so this can be a joint follow-up. - Severity: Low
- Raised by another reviewer: No
Issue 3: The new unit tests can pass without exercising the property they name, and may not run in CI
- Location:
TestUtilsTest.java(allocatesNonOverlappingPortRanges,allocatesBindablePort) - Problem:
allocatesNonOverlappingPortRangesdraws two random 10-port ranges from a 20000-port window; if theALLOCATED_PORT_RANGESoverlap check were deleted, the test would still pass with probability above 99.9%, so it has weak failure power.allocatesBindablePortonly checks the first port of a 1-port range. Separately, this module is normally driven through*ITclasses, and I could not confirm from the diff alone that*Testclasses inconnector-seatunnel-e2e-baseare executed by the CI surefire/failsafe configuration. - Potential risk: The test gives a false sense of coverage for the de-duplication logic.
- Best improvement: Make the overlap test deterministic, for example allocate a large
portCount(such as 10000 out of the 20001-port window) twice and assert the second call either returns a disjoint range or throws; or loop 50 allocations of 100 and assert pairwise disjointness. Please also confirm the class is picked up by CI (the forkBuildjob log should listTestUtilsTest). - Severity: Low
- Raised by another reviewer: No
2. Code Quality Assessment
2.1 Coding Standards
Good. Formatting follows Spotless, the new test file has the Apache license header, and the helper reuses the idiom already accepted in #11630. The new public method getAvailablePort and the 10000-30000 constants would benefit from a short comment on why the window avoids the OS ephemeral range (the engine-server helper has one); optional.
2.2 Test Coverage and Test Stability
Stability rating: Risk present (low). The change itself reduces flakiness, and nothing here adds Thread.sleep, fixed ports, or shared mutable state across tests beyond the intentionally synchronized registry. The residual risks are the unavoidable probe-then-bind window, the never-released registry (Issue 2), and the weak overlap assertion (Issue 3). Evidence: TestUtils.java:43-57 (synchronized allocation), TestUtils.java:67-72 (bind probe closes sockets before Hazelcast binds).
Fork CI Build on this head is green.
2.3 Documentation Updates
Not applicable; test-only change with no user-facing impact.
3. Architectural Soundness
3.1 Elegance
Long-term solution in spirit, partially applied: the helper is the right abstraction, but it is duplicated between seatunnel-engine-server test utils and connector-seatunnel-e2e-base test utils, and the module still contains two private getAvailablePort() variants (BackpressureSlowSinkIT.java:328, CheckpointMonitorStartupRaceIT.java:421) that allocate a single OS-ephemeral port.
3.2 Maintainability
Acceptable. Duplicating the helper across modules is understandable since an e2e module should not depend on engine-server test classes, but a shared test-jar utility (for example in seatunnel-engine-common test scope) would remove the drift risk. Not needed for this PR.
3.3 Extensibility
Fine: other tests can call TestUtils.getAvailablePort(n) directly.
3.4 Historical-Version Compatibility
Not applicable (tests only).
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| 1 | Other in-JVM engine-e2e tests still hardcode port: 5801; scope not stated in the description |
ClusterFaultToleranceIT.java:779, :990; SplitClusterFaultToleranceIT.java:1305 |
Low |
| 2 | Allocated port ranges are never released | TestUtils.java:41, :52 |
Low |
| 3 | Overlap test has weak failure power; unclear whether TestUtilsTest runs in CI |
TestUtilsTest.java |
Low |
5. Merge Recommendation
Conclusion: Ready to merge
- Blockers - must be fixed: none found.
- Recommended fixes - non-blocking: Issue 3 (make the overlap test deterministic and confirm it runs in CI), Issue 1 (state the scope or convert the remaining classes), Issue 2 (optional release hook).
Overall assessment: a sound, low-risk test-infrastructure improvement that follows the approach already accepted in #11630 and correctly keeps one shared start port per cluster so tcp-ip discovery still works. No production code is touched. CI on this head is green; the branch is 23 commits behind dev and mergeable_state is blocked (awaiting review), which is metadata only.
Better alternative: a single shared test utility used by both the engine-server and e2e modules, as a later cleanup.
|
The CI fact cited in my previous review has changed: Build for the current unchanged head is now passing. CI was previously the only remaining blocker; CI is now passing, so my technical conclusion changes to approve. I do not see a new source-side blocker from Daniel's review. This branch is behind the latest dev base, which I have recorded as merge metadata only; because the current head CI is green, that fact alone does not call for an additional source change. I have read-only review controls, so this COMMENT does not change GitHub's displayed review decision; a write-capable maintainer must perform any final approval or dismissal action. |
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks again for keeping this port-isolation work moving, @JeremyXin! The new head (8883bd36f67) is a merge of dev into the branch; I re-read the entire current diff against dev from scratch and the PR content is unchanged from the head I reviewed before (13610609f60). Details below. This is a static analysis only; nothing was built or executed locally.
What Problem Does This PR Solve?
User pain point: WorkerTagClusterTest (hardcoded start port 5801) and RecordSerializerIT (hardcoded 5901) build their Hazelcast YAML with a fixed starting port, so concurrent clusters on one CI host can race for the same range.
Fix approach: Add TestUtils.getAvailablePort(int portCount) to the engine-e2e module (random start in 10000-30000, whole range probed for bindability, de-duplicated within the JVM) and give every member of one test cluster the same start port from one 100-port range.
One-sentence summary: Each of these two test clusters now gets its own free, non-overlapping Hazelcast port range instead of a hardcoded one.
1. Code Change Review
1.1 Core Logic Analysis
Test-only change; no production code is touched.
WorkerTagClusterTest.before()andRecordSerializerIT.setUp()callTestUtils.getAvailablePort(100)once and pass the same value to both members, sotcp-ipdiscovery (member-list: localhost) still works: the first member bindsport, the second auto-increments.TestUtils.java:41-75allocation issynchronized, checks the in-JVM registry first, then probes each port with aServerSocketbind. Range arithmetic (nextInt(MIN, MAX - portCount + 2)) keepsrangeEnd <= MAX.getHazelcastConfigsignature changed (protected static); I found no other caller in the module on this head.
1.2 Compatibility Impact
Fully compatible: test code only.
1.3 Performance / Side-Effect Analysis
At most ~100 bind probes per allocation; negligible next to starting Hazelcast. The registry is never released (Issue 2, low).
1.4 Error Handling and Logging
Clear exceptions for invalid count and exhausted attempts. No blocking issues found. The three non-blocking points from my previous review are still open (carryover, not new):
Issue 1: Other in-JVM engine-e2e tests still hardcode port: 5801
- Location:
ClusterFaultToleranceIT.java:779,:990;SplitClusterFaultToleranceIT.java:1305 - Problem: Same hardcoded pattern remains; the PR title says "additional E2E tests" but the scope is not stated.
- Potential risk: The flakiness class can still occur in those classes.
- Best improvement: State in the description that this is a partial follow-up (container-based tests that use fixed mapped ports are intentionally untouched), or convert these in a tracked follow-up.
- Severity: Low
- Raised by another reviewer: No
Issue 2: Allocated port ranges are never released
- Location:
TestUtils.java:41,:52 - Problem:
ALLOCATED_PORT_RANGESonly grows (about 200 ranges of 100 fit in the window). - Potential risk: Latent trap only if many more classes adopt the helper in one JVM.
- Best improvement: Optional release hook or a short comment documenting the limit.
- Severity: Low
- Raised by another reviewer: No
Issue 3: TestUtilsTest.allocatesNonOverlappingPortRanges has weak failure power
- Location:
TestUtilsTest.java:36-41 - Problem: Two random 10-port ranges from a 20000-port window almost never overlap, so deleting the overlap check would still pass this test with very high probability.
- Potential risk: False sense of coverage for the de-duplication logic.
- Best improvement: Make it deterministic, e.g. loop many allocations and assert pairwise disjointness, or allocate near the full window and assert the second call is disjoint or throws.
- Severity: Low
- Raised by another reviewer: No
2. Code Quality Assessment
2.1 Coding Standards
Good; license header present, Spotless-style formatting.
2.2 Test Coverage and Test Stability
Stability rating: Risk present (low). The change reduces flakiness and adds no Thread.sleep or new fixed ports; residual risk is the inherent probe-then-bind window plus Issues 2 and 3.
2.3 Documentation Updates
Not applicable.
3. Architectural Soundness
3.1 Elegance
Long-term direction, partially applied (helper is duplicated from the engine-server test utils; other classes still hardcode ports).
3.2 Maintainability
Acceptable; a shared test utility would remove the drift risk later.
3.3 Extensibility
Fine; other tests can call TestUtils.getAvailablePort(n).
3.4 Historical-Version Compatibility
Not applicable.
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| 1 | Other in-JVM tests still hardcode 5801; scope not stated |
ClusterFaultToleranceIT.java:779, :990; SplitClusterFaultToleranceIT.java:1305 |
Low |
| 2 | Port ranges never released | TestUtils.java:41, :52 |
Low |
| 3 | Overlap test has weak failure power | TestUtilsTest.java:36-41 |
Low |
5. Merge Recommendation
Conclusion: Ready to merge
- Blockers - must be fixed: none found.
- Recommended non-blocking: Issue 3, Issue 1, Issue 2.
CI: Build is SUCCESS on the current head, and GitHub reports the PR as mergeable (no conflicts); the remaining BLOCKED state is just the required human approval. Being behind dev is metadata only. Since no technical blocker remains and CI is green, I am approving; note that I have no write-level review controls, so a committer must perform the final merge.
Purpose of this pull request
Follow up on #11630.
WorkerTagClusterTestandRecordSerializerITstill construct Hazelcast YAML with hardcoded starting ports, which can cause port conflicts when tests run concurrently in CI.This PR allocates a bindable port range for each test cluster and gives all members of that cluster the same starting port. It also adds E2E test utility coverage for port allocation, non-overlapping ranges, and invalid input.
Does this PR introduce any user-facing change?
No. The changes are limited to test code.
How was this patch tested?
spotless:checkpassed forconnector-seatunnel-e2e-base.git diff --checkpassed.Check list
New License Guide
incompatible-changes.mdto describe the incompatibility caused by this PR.