From edced031e7320ea9e1216d127432d313565bca7e Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Tue, 15 Nov 2022 09:25:35 +0000 Subject: [PATCH] Fix failing build on MacOS (#2313) # Motivation Currently, the main branch fails to build for me since the `testSimpleMPTCP()` can't compile. This is due to the fact that the `getMPTCPInfo()` method is only available on Linux. # Modification Add `#if os(Linux)` around the `testSimpleMPTCP()`. # Result Main builds on MacOS again. --- Tests/NIOPosixTests/SocketChannelTest.swift | 63 +++++++++++---------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/Tests/NIOPosixTests/SocketChannelTest.swift b/Tests/NIOPosixTests/SocketChannelTest.swift index 082cb70bc..8a8ebae3a 100644 --- a/Tests/NIOPosixTests/SocketChannelTest.swift +++ b/Tests/NIOPosixTests/SocketChannelTest.swift @@ -906,43 +906,48 @@ public final class SocketChannelTest : XCTestCase { XCTAssertNoThrow(try serverSocket.close()) } + func testSimpleMPTCP() throws { - let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) - defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) } + #if os(Linux) + let group = MultiThreadedEventLoopGroup(numberOfThreads: 1) + defer { XCTAssertNoThrow(try group.syncShutdownGracefully()) } - let serverChannel: Channel + let serverChannel: Channel - do { - serverChannel = try ServerBootstrap(group: group) - .enableMPTCP(true) - .bind(host: "127.0.0.1", port: 0) - .wait() - } catch let error as IOError { - // Older Linux kernel versions don't support MPTCP, which is fine. - if error.errnoCode != EINVAL && error.errnoCode != EPROTONOSUPPORT { - XCTFail("Unexpected error: \(error)") + do { + serverChannel = try ServerBootstrap(group: group) + .enableMPTCP(true) + .bind(host: "127.0.0.1", port: 0) + .wait() + } catch let error as IOError { + // Older Linux kernel versions don't support MPTCP, which is fine. + if error.errnoCode != EINVAL && error.errnoCode != EPROTONOSUPPORT { + XCTFail("Unexpected error: \(error)") + } + return } - return - } - let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group) - .enableMPTCP(true) - .connect(to: serverChannel.localAddress!) - .wait()) + let clientChannel = try assertNoThrowWithValue(ClientBootstrap(group: group) + .enableMPTCP(true) + .connect(to: serverChannel.localAddress!) + .wait()) - do { - let serverInfo = try (serverChannel as? SocketOptionProvider)?.getMPTCPInfo().wait() - let clientInfo = try (clientChannel as? SocketOptionProvider)?.getMPTCPInfo().wait() + do { + let serverInfo = try (serverChannel as? SocketOptionProvider)?.getMPTCPInfo().wait() + let clientInfo = try (clientChannel as? SocketOptionProvider)?.getMPTCPInfo().wait() - XCTAssertNotNil(serverInfo) - XCTAssertNotNil(clientInfo) - } catch let error as IOError { - // Some Linux kernel versions do support MPTCP but don't support the MPTCP_INFO - // option. - XCTAssertEqual(error.errnoCode, EOPNOTSUPP, "Unexpected error: \(error)") - return - } + XCTAssertNotNil(serverInfo) + XCTAssertNotNil(clientInfo) + } catch let error as IOError { + // Some Linux kernel versions do support MPTCP but don't support the MPTCP_INFO + // option. + XCTAssertEqual(error.errnoCode, EOPNOTSUPP, "Unexpected error: \(error)") + return + } + + #endif } + } class DropAllReadsOnTheFloorHandler: ChannelDuplexHandler {