Skip to content

test: keep other programs off the IPv4 port of the DAP loopback tests - #2035

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/dap-loopback-test-reserves-the-ipv4-port
Nov 21, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/dap-loopback-test-reserves-the-ipv4-port

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

DAPLoopbackConnectionTest.withoutAnAddressTheWaitForTheDAPServerSeesItsSocketOnTheIPv6LoopbackAddress
failed in the 2026.3 job of #2032, which doesn't touch DAP:

org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
    at ...DAPLoopbackConnectionTest.java:59

The three tests of the class listen on a port of ::1 that the system
picks, and expect nothing on the same port of 127.0.0.1: a connection
there must be refused, and a client without an address must fall through
to ::1. A port that is free on ::1 can be in use on 127.0.0.1 by
another program or test, and then the connection is accepted and the
test fails.

The tests now also bind that port of 127.0.0.1 with a socket that
doesn't listen, and take another port when it is in use. While it is
bound, nothing else can listen there, so a connection to it is refused.

Tests

Checked on macOS, with another process as the other program:

  • a program can listen on 127.0.0.1 on the port that the test has on ::1, and a connection to it is then accepted, which is the failure of the job;
  • then the reservation can't bind the port (Address already in use), and the test takes another one;
  • once the port is reserved, another program can't listen on it, even with SO_REUSEADDR, nor can a ServerSocket with SO_REUSEADDR, and a connection to it is refused.

DAPLoopbackConnectionTest passes on a default JVM and on one that prefers IPv6 addresses.

Not here: two tests of SocketStreamConnectionProviderTest have the same race, testWithoutAHostItReachesALanguageServerWhichListensOnTheIPv6LoopbackAddressOnly and testAnIPv4AddressAsTheHostIsNotTriedOverIPv6. #2033 and #2034 change that file, so they can follow once those are merged.

`DAPLoopbackConnectionTest.withoutAnAddressTheWaitForTheDAPServerSeesItsSocketOnTheIPv6LoopbackAddress`
failed in the 2026.3 job of redhat-developer#2032, which doesn't touch DAP:

    org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
        at ...DAPLoopbackConnectionTest.java:59

The three tests of the class listen on a port of `::1` that the system
picks, and expect nothing on the same port of `127.0.0.1`: a connection
there must be refused, and a client without an address must fall through
to `::1`. A port that is free on `::1` can be in use on `127.0.0.1` by
another program or test, and then the connection is accepted and the
test fails.

The tests now also bind that port of `127.0.0.1` with a socket that
doesn't listen, and take another port when it is in use. While it is
bound, nothing else can listen there, so a connection to it is refused.
@lagergren lagergren added this to the 0.30.2 milestone Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Updated loopback connection tests to verify server readiness and port availability across IPv4 and IPv6.
    • Added retries when reserving a test port.

The loopback tests now use an IPv6-only server paired with an IPv4 socket reservation on the same port. The fixture retries failed reservations up to 10 times and closes both sockets after a failed attempt.

Changes: Loopback connection tests

Layer / File(s) Summary
Port reservation fixture and test updates
src/test/java/com/redhat/devtools/lsp4ij/dap/DAPLoopbackConnectionTest.java
The no-address, IPv4 failure, and readiness tests use the IPv6-only fixture. The fixture reserves the same port on IPv4, retries up to 10 times, and closes both sockets after a failed reservation. The readiness test closes the IPv6 server before checking port availability.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: Minimal · up to 804f3

This test-only change makes the loopback connection tests more reliable by holding the IPv4 side of the port while the IPv6 server runs. It does not affect production behavior. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the DAP loopback tests now keep other programs off the IPv4 port. The raw summary confirms a non-listening IPv4 socket reserves that port in DAPLoopbackConnectionTest.…
Description check Passed The description explains the flaky failure in the 2026.3 job, the cause (a port free on ::1 may be in use on 127.0.0.1), the fix (reserve the IPv4 port with a non-listening socket and retry on another…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the DAP loopback tests now keep other programs off the IPv4 port. The raw summary confirms a non-listening IPv4 socket reserves that port in DAPLoopbackConnectionTest. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description explains the flaky failure in the 2026.3 job, the cause (a port free on ::1 may be in use on 127.0.0.1), the fix (reserve the IPv4 port with a non-listening socket and retry on another port), the macOS test steps, and the out-of-scope similar races. It relates directly to the changeset.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 66e2d20c-7a5e-430e-8cbe-226b6b92dbd8
Commits

Reviewing files that changed from the base of the PR and between b354c38 and 804f35f.

Files selected for processing: 1

  • src/test/java/com/redhat/devtools/lsp4ij/dap/DAPLoopbackConnectionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.43%. Comparing base (b354c38) to head (804f35f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2035      +/-   ##
==========================================
+ Coverage   49.39%   49.43%   +0.03%     
==========================================
  Files         813      813              
  Lines       33323    33323              
  Branches     5191     5191              
==========================================
+ Hits        16461    16472      +11     
+ Misses      14290    14278      -12     
- Partials     2572     2573       +1     

☔ 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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 873746d into redhat-developer:main Nov 21, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 21, 2026
…server on ::1 only (#2043)

Two tests of `SocketStreamConnectionProviderTest` have the race that
#2035 removes from `DAPLoopbackConnectionTest`. They listen on a port of
`::1` that the system picks, and expect nothing on the same port of
`127.0.0.1`:

- `testWithoutAHostItReachesALanguageServerWhichListensOnTheIPv6LoopbackAddressOnly`
  expects a provider without a host to fall through to `::1`. With
  another program on that port of `127.0.0.1`, the provider connects
  there, and the test waits for a connection to its server that never
  comes;
- `testAnIPv4AddressAsTheHostIsNotTriedOverIPv6` expects the connection
  to `127.0.0.1` to be refused, and it is accepted.

`IPv6OnlyLoopbackPort` listens on a port of `::1` and binds the same port
of `127.0.0.1` with a socket that doesn't listen, and takes another port
when it is in use there, as #2035 does. While it is bound, nothing else
can listen there. Its server's accept times out after 10 seconds rather
than hang a test.

Test: `SocketStreamConnectionProviderTest` passes on a default JVM and on
one that prefers IPv6 addresses (30 tests).

`DAPLoopbackConnectionTest` keeps its own copy of the helper in #2035, which is still open; once both are merged, it can use `IPv6OnlyLoopbackPort` too.
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