swift-server / async-http-client

HTTP client library built on SwiftNIO

Home Page:https://swiftpackageindex.com/swift-server/async-http-client/main/documentation/asynchttpclient

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add unit tests for `NWWaitingHandler`

dnadoba opened this issue · comments

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.

commented

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.

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