Skip to content
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

Add unit tests for NWWaitingHandler #589

Closed
dnadoba opened this issue Jun 2, 2022 · 2 comments · Fixed by #702
Closed

Add unit tests for NWWaitingHandler #589

dnadoba opened this issue Jun 2, 2022 · 2 comments · Fixed by #702
Labels
good first issue Good for newcomers

Comments

@dnadoba
Copy link
Collaborator

dnadoba commented Jun 2, 2022

When we added NWWaitingHandler in #588 we didn’t add a unit test for the NWWaitingHandler. This is because we need to make an enhancement to NIOTransportServices to make the WaitingForConnectivity event initialiser public. This is tracked as a separate issue in apple/swift-nio-transport-services#147 and must be resolved first.

The unit test can be implemented by using an EmbeddedChannel and sending an NIOTSNetworkEvents.WaitingForConnectivity through fireUserInboundEventTriggered(_:). An example usage of EmbeddedChannel and fireUserInboundEventTriggered(_:) can be found here:

let tlsEventsHandler = TLSEventsHandler(deadline: nil)
XCTAssertNil(tlsEventsHandler.tlsEstablishedFuture)
let embedded = EmbeddedChannel(handlers: [tlsEventsHandler])
XCTAssertNotNil(tlsEventsHandler.tlsEstablishedFuture)
XCTAssertNoThrow(try embedded.connect(to: .makeAddressResolvingHost("localhost", port: 0)).wait())
embedded.pipeline.fireUserInboundEventTriggered(TLSUserEvent.handshakeCompleted(negotiatedProtocol: "abcd1234"))
XCTAssertEqual(try XCTUnwrap(tlsEventsHandler.tlsEstablishedFuture).wait(), "abcd1234")

This should be straight forward and a good first starter issue. If you have more questions please don't hesitate to ask here.

@NiwakaDev
Copy link

Hi, @dnadoba.

I'd like to address this issue.

This is tracked as a separate issue in apple/swift-nio-transport-services#147 and must be resolved first.

Have this been resolved already? If so, I'd like to work on this issue next week.

@dnadoba
Copy link
Collaborator Author

dnadoba commented Mar 21, 2023

Yes, the initialisers are now public and you can address the issue. PRs welcome :)

natikgadzhi added a commit to natikgadzhi/async-http-client that referenced this issue Aug 3, 2023
Motivation:

Closes swift-server#589. Since we already have a public initializer for
NIOTSNetworkEvents.WaitingForConnectivity, we should add unit tests for
the handler now that it's straightforward.

Modifications:

The tests are in their own file `Tests/NWWaitingHandlerTests.swift`.
dnadoba added a commit that referenced this issue Aug 14, 2023
* Add unit tests for NWWaitingHandler

Motivation:

Closes #589. Since we already have a public initializer for
NIOTSNetworkEvents.WaitingForConnectivity, we should add unit tests for
the handler now that it's straightforward.

Modifications:

The tests are in their own file `Tests/NWWaitingHandlerTests.swift`.

* Bump swift-nio-transport-services to 1.13.0

* SwiftFormat@0.48.8

* Apply suggestions from code review

Co-authored-by: David Nadoba <dnadoba@gmail.com>

---------

Co-authored-by: David Nadoba <dnadoba@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants