Skip to content

Add unit tests for NWWaitingHandler #589

Closed
@dnadoba

Description

@dnadoba

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions