diff --git a/Tests/NIOPosixTests/BootstrapTest.swift b/Tests/NIOPosixTests/BootstrapTest.swift index 689b5b37eb..4eb67e1f48 100644 --- a/Tests/NIOPosixTests/BootstrapTest.swift +++ b/Tests/NIOPosixTests/BootstrapTest.swift @@ -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")