Skip to content

Commit 324bc65

Browse files
authored
Fix last remaining test on Android (#2457)
Motivation Get all tests passing on Android AArch64 Modifications - Check if localhost is set for IPv6 in BootstrapTest/testClientBindWorksOnSocketsBoundToEitherIPv4OrIPv6Only, and use ip6-localhost if not Result All tests pass natively on Android AArch64
1 parent 0ec899a commit 324bc65

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Tests/NIOPosixTests/BootstrapTest.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,21 @@ class BootstrapTest: XCTestCase {
644644

645645
var maybeChannel1: Channel? = nil
646646
// Try 2: Connect to "localhost", this will do Happy Eyeballs.
647+
var localhost = "localhost"
648+
// Some platforms don't define "localhost" for IPv6, so check that
649+
// and use "ip6-localhost" instead.
650+
if !isIPv4 {
651+
let hostResolver = GetaddrinfoResolver(loop: group.next(), aiSocktype: .stream, aiProtocol: .tcp)
652+
let hostv6 = try! hostResolver.initiateAAAAQuery(host: "localhost", port: 8088).wait()
653+
if hostv6.isEmpty {
654+
localhost = "ip6-localhost"
655+
}
656+
}
657+
647658
XCTAssertNoThrow(maybeChannel1 = try ClientBootstrap(group: self.group)
648659
.channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
649660
.bind(to: clientLocalAddressWholeInterface)
650-
.connect(host: "localhost", port: server1LocalAddress.port!)
661+
.connect(host: localhost, port: server1LocalAddress.port!)
651662
.wait())
652663
guard let myChannel1 = maybeChannel1, let myChannel1Address = myChannel1.localAddress else {
653664
XCTFail("can't connect channel 1")

0 commit comments

Comments
 (0)