Skip to content

Commit

Permalink
improve test reliability regarding EPOLLHUP (#326)
Browse files Browse the repository at this point in the history
Motivation:

PR #286 started processing EPOLLHUPs. Sadly epoll also immediately
throws EPOLLHUP at you if you register a socket that isn't either
connected or listening. This fixes two more instances of this problem.

Modifications:

made sure sockets that are registered are either listening or
connected (and before we let the Selector wait for events)

Result:

tests should be more reliable
  • Loading branch information
weissi authored and Lukasa committed Apr 18, 2018
1 parent 9326f74 commit 17af3c7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Tests/NIOTests/EventLoopTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ public class EventLoopTest : XCTestCase {
// We're going to create and register a channel, but not actually attempt to do anything with it.
let wedgeHandler = WedgeOpenHandler()
let channel = try SocketChannel(eventLoop: loop, protocolFamily: AF_INET)
try channel.pipeline.add(handler: wedgeHandler).then {
channel.register()
}.then {
// connecting here to stop epoll from throwing EPOLLHUP at us
channel.connect(to: serverChannel.localAddress!)
_ = try channel.eventLoop.submit {
channel.pipeline.add(handler: wedgeHandler).then {
channel.register()
}.then {
// connecting here to stop epoll from throwing EPOLLHUP at us
channel.connect(to: serverChannel.localAddress!)
}
}.wait()

// Now we're going to start closing the event loop. This should not immediately succeed.
Expand Down Expand Up @@ -304,9 +306,14 @@ public class EventLoopTest : XCTestCase {
let group = MultiThreadedEventLoopGroup(numThreads: 1)
let eventLoop = group.next()
let assertHandler = AssertHandler()
let serverSocket = try ServerBootstrap(group: group).bind(host: "localhost", port: 0).wait()
let channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: AF_INET)
try channel.pipeline.add(handler: assertHandler).wait()
try channel.register().wait()
_ = try channel.eventLoop.submit {
channel.register().then {
channel.connect(to: serverSocket.localAddress!)
}
}.wait()
XCTAssertFalse(channel.closeFuture.isFulfilled)
try group.syncShutdownGracefully()
XCTAssertTrue(assertHandler.groupIsShutdown.compareAndExchange(expected: false, desired: true))
Expand Down

0 comments on commit 17af3c7

Please sign in to comment.