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:
parent
e7403c35ca
commit
251e9e7613
|
|
@ -67,10 +67,13 @@ final class ReadRecorder<DataType>: ChannelInboundHandler {
|
||||||
var readWaiters: [Int: EventLoopPromise<[DataType]>] = [:]
|
var readWaiters: [Int: EventLoopPromise<[DataType]>] = [:]
|
||||||
var readCompleteCount = 0
|
var readCompleteCount = 0
|
||||||
|
|
||||||
|
func handlerAdded(context: ChannelHandlerContext) {
|
||||||
|
self.loop = context.eventLoop
|
||||||
|
}
|
||||||
|
|
||||||
func channelRegistered(context: ChannelHandlerContext) {
|
func channelRegistered(context: ChannelHandlerContext) {
|
||||||
XCTAssertEqual(.fresh, self.state)
|
XCTAssertEqual(.fresh, self.state)
|
||||||
self.state = .registered
|
self.state = .registered
|
||||||
self.loop = context.eventLoop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func channelActive(context: ChannelHandlerContext) {
|
func channelActive(context: ChannelHandlerContext) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue