Avoid race in datagram tests (#185)

Motivation:

The datagram tests use a handler which sets its event loop in
`channelRegistered`. A function on the handler is called which relies on
the EL being set. However, this can race: the function can be called
before `channelRegistered` is called.

Modifications:

- set the EL in `handlerAdded`

Result:

Fewer crashes
This commit is contained in:
George Barnett 2023-09-04 11:28:27 +01:00 committed by GitHub
parent e7403c35ca
commit 251e9e7613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -67,10 +67,13 @@ final class ReadRecorder<DataType>: ChannelInboundHandler {
var readWaiters: [Int: EventLoopPromise<[DataType]>] = [:]
var readCompleteCount = 0
func handlerAdded(context: ChannelHandlerContext) {
self.loop = context.eventLoop
}
func channelRegistered(context: ChannelHandlerContext) {
XCTAssertEqual(.fresh, self.state)
self.state = .registered
self.loop = context.eventLoop
}
func channelActive(context: ChannelHandlerContext) {