Skip to content

Commit

Permalink
Fix last remaining test on Android (#2457)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
finagolfin authored Jul 4, 2023
1 parent 0ec899a commit 324bc65
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Tests/NIOPosixTests/BootstrapTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,21 @@ class BootstrapTest: XCTestCase {

var maybeChannel1: Channel? = nil
// Try 2: Connect to "localhost", this will do Happy Eyeballs.
var localhost = "localhost"
// Some platforms don't define "localhost" for IPv6, so check that
// and use "ip6-localhost" instead.
if !isIPv4 {
let hostResolver = GetaddrinfoResolver(loop: group.next(), aiSocktype: .stream, aiProtocol: .tcp)
let hostv6 = try! hostResolver.initiateAAAAQuery(host: "localhost", port: 8088).wait()
if hostv6.isEmpty {
localhost = "ip6-localhost"
}
}

XCTAssertNoThrow(maybeChannel1 = try ClientBootstrap(group: self.group)
.channelOption(ChannelOptions.socketOption(.so_reuseaddr), value: 1)
.bind(to: clientLocalAddressWholeInterface)
.connect(host: "localhost", port: server1LocalAddress.port!)
.connect(host: localhost, port: server1LocalAddress.port!)
.wait())
guard let myChannel1 = maybeChannel1, let myChannel1Address = myChannel1.localAddress else {
XCTFail("can't connect channel 1")
Expand Down

0 comments on commit 324bc65

Please sign in to comment.