-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fire the pipelines error caught method when NWConnection's state changes to failed #187
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8be4802
Fire the pipelines error caughted method when NWConnection's state c…
Cartisim 1b4727a
Added check if failed error is ChannelError.eof and added a unit test…
Cartisim 39d42b0
Completing a promise for the error caught
Cartisim db65ef5
Fixed Typo
Cartisim c2571f3
Removed whitespace
Cartisim 0527987
Binding the listener to port 0 and connecting to listerner's localAdd…
Cartisim dd8df33
Merge branch 'apple:main' into forward-failed-state-error
Cartisim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -865,5 +865,61 @@ class NIOTSConnectionChannelTests: XCTestCase { | |
.wait() | ||
XCTAssertNoThrow(try connection.close().wait()) | ||
} | ||
|
||
func testErrorIsForwardedFromFailedConnectionState() throws { | ||
final class ForwardErrorHandler: ChannelDuplexHandler { | ||
typealias OutboundIn = ByteBuffer | ||
typealias InboundIn = ByteBuffer | ||
|
||
private let testCompletePromise: EventLoopPromise<Error> | ||
let listenerChannel: Channel | ||
|
||
init(testCompletePromise: EventLoopPromise<Error>, listenerChannel: Channel) { | ||
self.testCompletePromise = testCompletePromise | ||
self.listenerChannel = listenerChannel | ||
} | ||
func channelActive(context: ChannelHandlerContext) { | ||
let listenerErrorPromise = self.listenerChannel.eventLoop.next().makePromise(of: Error.self) | ||
listenerChannel | ||
.close() | ||
.whenSuccess { _ in | ||
context.channel.write(ByteBuffer(data: Data())) | ||
.whenFailure({ error in | ||
listenerErrorPromise.succeed(error) | ||
}) | ||
} | ||
} | ||
|
||
func errorCaught(context: ChannelHandlerContext, error: Error) { | ||
let error = error as? ChannelError | ||
XCTAssertNotEqual(error, ChannelError.eof) | ||
XCTAssertEqual(error, ChannelError.ioOnClosedChannel) | ||
Lukasa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
XCTAssertNotNil(error) | ||
testCompletePromise.succeed(error!) | ||
} | ||
} | ||
|
||
let listener = try NIOTSListenerBootstrap(group: self.group) | ||
.childChannelInitializer { channel in | ||
return channel.eventLoop.makeSucceededVoidFuture() | ||
} | ||
.bind(host: "127.0.0.1", port: 8080) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we |
||
.wait() | ||
|
||
let testCompletePromise = self.group.next().makePromise(of: Error.self) | ||
let connection = try NIOTSConnectionBootstrap(group: self.group) | ||
.channelInitializer { channel in | ||
channel.pipeline.addHandler( | ||
ForwardErrorHandler( | ||
testCompletePromise: testCompletePromise, | ||
listenerChannel: listener | ||
) | ||
) | ||
} | ||
.connect(host: "127.0.0.1", port: 8080) | ||
.wait() | ||
XCTAssertNoThrow(try connection.close().wait()) | ||
XCTAssertNoThrow(try testCompletePromise.futureResult.wait()) | ||
} | ||
} | ||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this path should complete the promise: we're testing for this happening in errorcaught, not on the write promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you cool with me just throwing the result of the write away?