diff --git a/Tests/NIOTests/BootstrapTest.swift b/Tests/NIOTests/BootstrapTest.swift index 3f8e8285f..bc4c6401b 100644 --- a/Tests/NIOTests/BootstrapTest.swift +++ b/Tests/NIOTests/BootstrapTest.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -import NIO +@testable import NIO import XCTest class BootstrapTest: XCTestCase { @@ -50,7 +50,7 @@ class BootstrapTest: XCTestCase { return channel.eventLoop.newSucceededFuture(result: ()) } .connect(to: serverChannel.localAddress!) - .wait()) + .wait(), message: "resolver debug info: \(try! resolverDebugInformation(eventLoop: group.next(),host: "localhost", previouslyReceivedResult: serverChannel.localAddress!))") defer { XCTAssertNoThrow(try client.syncCloseAcceptingAlreadyClosed()) } diff --git a/Tests/NIOTests/ChannelTests.swift b/Tests/NIOTests/ChannelTests.swift index cec76ba12..46d15825c 100644 --- a/Tests/NIOTests/ChannelTests.swift +++ b/Tests/NIOTests/ChannelTests.swift @@ -2402,7 +2402,7 @@ public class ChannelTests: XCTestCase { } let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group) .connect(to: serverChannel.localAddress!) - .wait()) + .wait(), message: "resolver debug info: \(try! resolverDebugInformation(eventLoop: group.next(),host: "localhost", previouslyReceivedResult: serverChannel.localAddress!))") XCTAssertNoThrow(try clientChannel.closeFuture.wait() as Void) } diff --git a/Tests/NIOTests/TestUtils.swift b/Tests/NIOTests/TestUtils.swift index cae25c1ce..2a908c8e5 100644 --- a/Tests/NIOTests/TestUtils.swift +++ b/Tests/NIOTests/TestUtils.swift @@ -166,11 +166,11 @@ func assertSetGetOptionOnOpenAndClosed(channel: Channel, optio } } -func assertNoThrowWithValue(_ body: @autoclosure () throws -> T, defaultValue: T? = nil, file: StaticString = #file, line: UInt = #line) throws -> T { +func assertNoThrowWithValue(_ body: @autoclosure () throws -> T, defaultValue: T? = nil, message: String? = nil, file: StaticString = #file, line: UInt = #line) throws -> T { do { return try body() } catch { - XCTFail("unexpected error \(error) thrown", file: file, line: line) + XCTFail("\(message.map { $0 + ": " } ?? "")unexpected error \(error) thrown", file: file, line: line) if let defaultValue = defaultValue { return defaultValue } else { @@ -178,3 +178,29 @@ func assertNoThrowWithValue(_ body: @autoclosure () throws -> T, defaultValue } } } + +func resolverDebugInformation(eventLoop: EventLoop, host: String, previouslyReceivedResult: SocketAddress) throws -> String { + func printSocketAddress(_ socketAddress: SocketAddress) -> String { + switch socketAddress { + case .unixDomainSocket(_): + return "uds" + case .v4(let sa): + var addr = sa.address + return addr.addressDescription() + case .v6(let sa): + var addr = sa.address + return addr.addressDescription() + } + } + let res = GetaddrinfoResolver(loop: eventLoop, aiSocktype: Posix.SOCK_STREAM, aiProtocol: Posix.IPPROTO_TCP) + let ipv6Results = try assertNoThrowWithValue(res.initiateAAAAQuery(host: host, port: 0).wait()).map(printSocketAddress) + let ipv4Results = try assertNoThrowWithValue(res.initiateAQuery(host: host, port: 0).wait()).map(printSocketAddress) + + return """ + when trying to resolve '\(host)' we've got the following results: + - previous try: \(printSocketAddress(previouslyReceivedResult)) + - all results: + IPv4: \(ipv4Results) + IPv6: \(ipv6Results) + """ +}