diff --git a/Sources/NIOPosix/Bootstrap.swift b/Sources/NIOPosix/Bootstrap.swift index ac696a372..c0f5a0e20 100644 --- a/Sources/NIOPosix/Bootstrap.swift +++ b/Sources/NIOPosix/Bootstrap.swift @@ -1023,8 +1023,6 @@ public final class NIOPipeBootstrap { } private func validateFileDescriptorIsNotAFile(_ descriptor: CInt) throws { - precondition(MultiThreadedEventLoopGroup.currentEventLoop == nil, - "limitation in SwiftNIO: cannot bootstrap PipeChannel on EventLoop") var s: stat = .init() try withUnsafeMutablePointer(to: &s) { ptr in try Posix.fstat(descriptor: descriptor, outStat: ptr) diff --git a/Tests/NIOPosixTests/BootstrapTest+XCTest.swift b/Tests/NIOPosixTests/BootstrapTest+XCTest.swift index def8287dc..4c387fa34 100644 --- a/Tests/NIOPosixTests/BootstrapTest+XCTest.swift +++ b/Tests/NIOPosixTests/BootstrapTest+XCTest.swift @@ -39,6 +39,7 @@ extension BootstrapTest { ("testPreConnectedSocketSetsChannelOptionsBeforeChannelInitializer", testPreConnectedSocketSetsChannelOptionsBeforeChannelInitializer), ("testDatagramBootstrapSetsChannelOptionsBeforeChannelInitializer", testDatagramBootstrapSetsChannelOptionsBeforeChannelInitializer), ("testPipeBootstrapSetsChannelOptionsBeforeChannelInitializer", testPipeBootstrapSetsChannelOptionsBeforeChannelInitializer), + ("testPipeBootstrapInEventLoop", testPipeBootstrapInEventLoop), ("testServerBootstrapAddsAcceptHandlerAfterServerChannelInitialiser", testServerBootstrapAddsAcceptHandlerAfterServerChannelInitialiser), ("testClientBootstrapValidatesWorkingELGsCorrectly", testClientBootstrapValidatesWorkingELGsCorrectly), ("testClientBootstrapRejectsNotWorkingELGsCorrectly", testClientBootstrapRejectsNotWorkingELGsCorrectly), diff --git a/Tests/NIOPosixTests/BootstrapTest.swift b/Tests/NIOPosixTests/BootstrapTest.swift index 70722e71c..72533f7a4 100644 --- a/Tests/NIOPosixTests/BootstrapTest.swift +++ b/Tests/NIOPosixTests/BootstrapTest.swift @@ -389,6 +389,32 @@ class BootstrapTest: XCTestCase { }) } + func testPipeBootstrapInEventLoop() { + let testGrp = DispatchGroup() + testGrp.enter() + + let eventLoop = self.group.next() + + eventLoop.execute { + do { + let pipe = Pipe() + let readHandle = NIOFileHandle(descriptor: pipe.fileHandleForReading.fileDescriptor) + let writeHandle = NIOFileHandle(descriptor: pipe.fileHandleForWriting.fileDescriptor) + _ = NIOPipeBootstrap(group: self.group) + .withPipes(inputDescriptor: try readHandle.takeDescriptorOwnership(), outputDescriptor: try writeHandle.takeDescriptorOwnership()) + .flatMap({ channel in + channel.close() + }).always({ _ in + testGrp.leave() + }) + } catch { + XCTFail("Failed to bootstrap pipechannel in eventloop: \(error)") + testGrp.leave() + } + } + testGrp.wait() + } + func testServerBootstrapAddsAcceptHandlerAfterServerChannelInitialiser() { // It's unclear if this is the right solution, see https://github.com/apple/swift-nio/issues/1392 let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)