Skip to content

test: let the socket tests pass on a JVM that prefers IPv6 addresses - #2034

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/socket-tests-on-an-ipv6-jvm
Nov 20, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:test/socket-tests-on-an-ipv6-jvm

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

On a JVM started with -Djava.net.preferIPv6Addresses=true,
InetAddress.getLoopbackAddress() is ::1, and six socket tests failed,
for the way they wrote the expected text, not for what LSP4IJ does:

  • SocketStreamConnectionProviderTest wrote the host before a port as
    HOST + ":" + port, which for 0:0:0:0:0:0:0:1 lacks the brackets
    that the provider writes, as it must:
    testConnectsToALanguageServerThatRunsAlreadyAndLeavesItRunningWhenItStops,
    testCannotStartWhenNoLanguageServerListens and
    testConnectionDescriptionForAttach.
  • UserDefinedSocketConnectionTest looked for the JVM's loopback address
    as getHostAddress() + ":" + port, so 0:0:0:0:0:0:0:1:6005 in
    connect to [::1]:6005 or 127.0.0.1:6005:
    testALanguageServerThatRunsAlreadyIsReachedOnTheLoopbackAddressWithoutAHost,
    testABlankHostIsTheLoopbackAddress and
    testALanguageServerWhichListensIsReachedOnTheLoopbackAddress.

The first now writes the host in brackets when it is an IPv6 address.
The second now checks both loopback addresses in the order the provider
tries them, the JVM's first, which also checks that order, where it
checked each address on its own before.

Follow-up to #2033, which adds a test of the IPv4 listener for such a JVM. The two touch different lines and merge cleanly.

Tests

  • On a JVM that prefers IPv6 addresses (JAVA_TOOL_OPTIONS=-Djava.net.preferIPv6Addresses=true), the 22 test classes that use loopback addresses had these six failures and no others (171 tests). With this change, SocketStreamConnectionProviderTest and UserDefinedSocketConnectionTest pass there, and on a default JVM (37 tests each).
  • With test: cover the three test gaps that CodeRabbit found in #1924, #1938 and #1986 #2033 merged in, both classes pass on a JVM that prefers IPv6 addresses too, its new IPv4 test included (38 tests).

On a JVM started with `-Djava.net.preferIPv6Addresses=true`,
`InetAddress.getLoopbackAddress()` is `::1`, and six socket tests failed,
for the way they wrote the expected text, not for what LSP4IJ does:

- `SocketStreamConnectionProviderTest` wrote the host before a port as
  `HOST + ":" + port`, which for `0:0:0:0:0:0:0:1` lacks the brackets
  that the provider writes, as it must:
  `testConnectsToALanguageServerThatRunsAlreadyAndLeavesItRunningWhenItStops`,
  `testCannotStartWhenNoLanguageServerListens` and
  `testConnectionDescriptionForAttach`.
- `UserDefinedSocketConnectionTest` looked for the JVM's loopback address
  as `getHostAddress() + ":" + port`, so `0:0:0:0:0:0:0:1:6005` in
  `connect to [::1]:6005 or 127.0.0.1:6005`:
  `testALanguageServerThatRunsAlreadyIsReachedOnTheLoopbackAddressWithoutAHost`,
  `testABlankHostIsTheLoopbackAddress` and
  `testALanguageServerWhichListensIsReachedOnTheLoopbackAddress`.

The first now writes the host in brackets when it is an IPv6 address.
The second now checks both loopback addresses in the order the provider
tries them, the JVM's first, which also checks that order, where it
checked each address on its own before.
@lagergren lagergren added this to the 0.30.2 milestone Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 130a5f29-3b48-4687-89eb-324a5a3b3582
Commits

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

Files selected for processing: 2

  • src/test/java/com/redhat/devtools/lsp4ij/server/SocketStreamConnectionProviderTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/server/definition/launching/UserDefinedSocketConnectionTest.java

@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.41%. Comparing base (b354c38) to head (ccee811).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2034      +/-   ##
==========================================
+ Coverage   49.39%   49.41%   +0.01%     
==========================================
  Files         813      813              
  Lines       33323    33323              
  Branches     5191     6848    +1657     
==========================================
+ Hits        16461    16466       +5     
+ Misses      14290    14287       -3     
+ Partials     2572     2570       -2     

☔ 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
lagergren merged commit 943adce into redhat-developer:main Nov 20, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 21, 2026
…#2035)

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