Repository navigation
test: let the socket tests pass on a JVM that prefers IPv6 addresses - #2034
Conversation
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.
|
Warning Review limit reachedThis 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. View limit details
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
Action not completed
|
…#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.
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:
SocketStreamConnectionProviderTestwrote the host before a port asHOST + ":" + port, which for0:0:0:0:0:0:0:1lacks the bracketsthat the provider writes, as it must:
testConnectsToALanguageServerThatRunsAlreadyAndLeavesItRunningWhenItStops,testCannotStartWhenNoLanguageServerListensandtestConnectionDescriptionForAttach.UserDefinedSocketConnectionTestlooked for the JVM's loopback addressas
getHostAddress() + ":" + port, so0:0:0:0:0:0:0:1:6005inconnect to [::1]:6005 or 127.0.0.1:6005:testALanguageServerThatRunsAlreadyIsReachedOnTheLoopbackAddressWithoutAHost,testABlankHostIsTheLoopbackAddressandtestALanguageServerWhichListensIsReachedOnTheLoopbackAddress.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
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,SocketStreamConnectionProviderTestandUserDefinedSocketConnectionTestpass there, and on a default JVM (37 tests each).