mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
more debugging for flaky tests (#545)
Motivation: We suspect a DNS resolver issue in one of our test harnesses to cause most of the flaky tests. This patch adds more debug information about the resolver to flaky tests. Modifications: print the resolver output when flaky tests fail Result: one step closer to no flaky tests
This commit is contained in:
1 parent
cf55bee323
commit
aa4c009fa7
3 files changed
+31
-5
No files matched your search
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -166,11 +166,11 @@ func assertSetGetOptionOnOpenAndClosed<T: ChannelOption>(channel: Channel, optio
|
||||
}
|
||||
}
|
||||
|
||||
func assertNoThrowWithValue<T>(_ body: @autoclosure () throws -> T, defaultValue: T? = nil, file: StaticString = #file, line: UInt = #line) throws -> T {
|
||||
func assertNoThrowWithValue<T>(_ 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<T>(_ 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)
|
||||
"""
|
||||
}
|
||||
Reference in new issue
Block a user