Skip to content

Commit

Permalink
Tolerate IPv6 address resolution failure (#2704)
Browse files Browse the repository at this point in the history
Motivation:

In some cases IPv6 loopback address resolution fails in tests. We should
tolerate this.

Modifications:

- Swallow SocketAddressError.unknown

Result:

Fewer flaky tests
  • Loading branch information
glbrntt committed Apr 22, 2024
1 parent fa540cf commit bfc1a2c
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions Tests/NIOPosixTests/DatagramChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,23 @@ class DatagramChannelTests: XCTestCase {
return
}

let channel1 = try buildChannel(group: self.group, host: "::1")
try channel1.setOption(ChannelOptions.explicitCongestionNotification, value: true).wait()
XCTAssertTrue(try channel1.getOption(ChannelOptions.explicitCongestionNotification).wait())

let channel2 = try buildChannel(group: self.group, host: "::1")
try channel2.setOption(ChannelOptions.explicitCongestionNotification, value: false).wait()
XCTAssertFalse(try channel2.getOption(ChannelOptions.explicitCongestionNotification).wait())
do {
let channel1 = try buildChannel(group: self.group, host: "::1")
try channel1.setOption(ChannelOptions.explicitCongestionNotification, value: true).wait()
XCTAssertTrue(try channel1.getOption(ChannelOptions.explicitCongestionNotification).wait())

let channel2 = try buildChannel(group: self.group, host: "::1")
try channel2.setOption(ChannelOptions.explicitCongestionNotification, value: false).wait()
XCTAssertFalse(try channel2.getOption(ChannelOptions.explicitCongestionNotification).wait())
} catch let error as SocketAddressError {
switch error {
case .unknown:
// IPv6 resolution can fail even if supported.
return
case .unsupported, .unixDomainSocketPathTooLong, .failedToParseIPString:
throw error
}
}
} ())
}

Expand Down Expand Up @@ -840,13 +850,23 @@ class DatagramChannelTests: XCTestCase {
return
}

let channel1 = try buildChannel(group: self.group, host: "::1")
try channel1.setOption(ChannelOptions.receivePacketInfo, value: true).wait()
XCTAssertTrue(try channel1.getOption(ChannelOptions.receivePacketInfo).wait())

let channel2 = try buildChannel(group: self.group, host: "::1")
try channel2.setOption(ChannelOptions.receivePacketInfo, value: false).wait()
XCTAssertFalse(try channel2.getOption(ChannelOptions.receivePacketInfo).wait())
do {
let channel1 = try buildChannel(group: self.group, host: "::1")
try channel1.setOption(ChannelOptions.receivePacketInfo, value: true).wait()
XCTAssertTrue(try channel1.getOption(ChannelOptions.receivePacketInfo).wait())

let channel2 = try buildChannel(group: self.group, host: "::1")
try channel2.setOption(ChannelOptions.receivePacketInfo, value: false).wait()
XCTAssertFalse(try channel2.getOption(ChannelOptions.receivePacketInfo).wait())
} catch let error as SocketAddressError {
switch error {
case .unknown:
// IPv6 resolution can fail even if supported.
return
case .unsupported, .unixDomainSocketPathTooLong, .failedToParseIPString:
throw error
}
}
} ())
}

Expand Down

0 comments on commit bfc1a2c

Please sign in to comment.