Skip to content

test: keep other programs off the IPv4 port of the socket tests of a server on ::1 only - #2043

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

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/socket-loopback-tests-reserve-the-ipv4-port

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

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.

…server on ::1 only

Two tests of `SocketStreamConnectionProviderTest` have the race that
redhat-developer#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 redhat-developer#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 (29 tests).
@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
    • Expanded automated checks for connections in IPv6-only loopback environments, covering both unspecified hosts and explicitly IPv4-addressed connections. These checks verify that the two connection scenarios continue to behave as expected. No user-facing functionality changes are included in this update.

Adds a test helper that binds an IPv6 loopback server and an IPv4 socket to the same port, retrying when the IPv4 bind fails. Updates two connection-provider tests to use the helper for host-unspecified and explicit IPv4-host cases.

Changes: IPv6 loopback connection tests

Layer / File(s) Summary
Create and use the shared-port listener
src/test/java/com/redhat/devtools/lsp4ij/server/IPv6OnlyLoopbackPort.java, src/test/java/com/redhat/devtools/lsp4ij/server/SocketStreamConnectionProviderTest.java
The helper binds IPv6 and IPv4 loopback sockets to the same port, retries failed IPv4 binds up to 10 attempts, and closes both sockets. Two connection tests use the helper while retaining their host-unspecified and explicit IPv4-host cases.

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

Change: Other

Merge Risk: Minimal · up to ac43f

This change only makes two socket tests more reliable by reserving the IPv4 loopback port. It has no production impact and is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: test-only helper that keeps other programs off the IPv4 loopback port used by IPv6-only socket tests. It is concise, specific, and matches the changeset (new IPv6OnlyL…
Description check Passed The description explains the race in two SocketStreamConnectionProviderTest tests, describes the new IPv6OnlyLoopbackPort helper (binds the IPv4 port, retries on conflict, 10-second accept timeout), a…
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: test-only helper that keeps other programs off the IPv4 loopback port used by IPv6-only socket tests. It is concise, specific, and matches the changeset (new IPv6OnlyLoopbackPort helper used in SocketStreamConnectionProviderTest). The 'test:' prefix is a conventional commit style and does not reduce clarity.

Full details: Description check

Explanation

The description explains the race in two SocketStreamConnectionProviderTest tests, describes the new IPv6OnlyLoopbackPort helper (binds the IPv4 port, retries on conflict, 10-second accept timeout), and states the test validation. This matches 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: 712631b5-ea6d-4336-8712-224fde608127
Commits

Reviewing files that changed from the base of the PR and between 0af1afc and ac43f38.

Files selected for processing: 2

  • src/test/java/com/redhat/devtools/lsp4ij/server/IPv6OnlyLoopbackPort.java
  • src/test/java/com/redhat/devtools/lsp4ij/server/SocketStreamConnectionProviderTest.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.40%. Comparing base (0af1afc) to head (ac43f38).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2043      +/-   ##
==========================================
- Coverage   49.44%   49.40%   -0.04%     
==========================================
  Files         813      813              
  Lines       33324    33324              
  Branches     5191     5191              
==========================================
- Hits        16478    16465      -13     
- Misses      14272    14282      +10     
- Partials     2574     2577       +3     

☔ 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 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 30adef2 into redhat-developer:main Nov 21, 2026
9 checks passed
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