Skip to content

Commit

Permalink
testConnect() declared a custom Socket but never used it.
Browse files Browse the repository at this point in the history
Motivation:

testConnect() should use its custom Socket implementation.

Modifications:

Make the test use the custom Socket

Result:

Correct test
  • Loading branch information
normanmaurer committed Apr 18, 2018
1 parent 1360fc6 commit 115a558
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Tests/NIOTests/SocketChannelTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,36 +195,41 @@ public class SocketChannelTest : XCTestCase {
}
}

let group = MultiThreadedEventLoopGroup(numThreads: 1)
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
}

class ConnectSocket: Socket {
init() throws {
private let promise: EventLoopPromise<Void>
init(promise: EventLoopPromise<Void>) throws {
self.promise = promise
try super.init(protocolFamily: PF_INET, type: Posix.SOCK_STREAM)
}

override func connect(to address: SocketAddress) throws -> Bool {
self.promise.succeed(result: ())
return true
}
}

let group = MultiThreadedEventLoopGroup(numThreads: 1)
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
}
let serverChannel = try ServerBootstrap(group: group).bind(host: "127.0.0.1", port: 0).wait()
defer {
XCTAssertNoThrow(try serverChannel.close().wait())
}
let channel = try SocketChannel(eventLoop: group.next() as! SelectableEventLoop, protocolFamily: PF_INET)
let eventLoop = group.next()
let connectPromise: EventLoopPromise<Void> = eventLoop.newPromise()

let channel = try SocketChannel(socket: ConnectSocket(promise: connectPromise), parent: nil, eventLoop: eventLoop as! SelectableEventLoop)
let promise: EventLoopPromise<Void> = channel.eventLoop.newPromise()

XCTAssertNoThrow(try channel.pipeline.add(handler: ActiveVerificationHandler(promise)).then {
channel.register()
}.then {
channel.connect(to: serverChannel.localAddress!)
channel.connect(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 9999))
}.then {
channel.close()
}.wait())

XCTAssertNoThrow(try channel.close().wait())
XCTAssertNoThrow(try channel.closeFuture.wait())
XCTAssertNoThrow(try promise.futureResult.wait())
XCTAssertNoThrow(try connectPromise.futureResult.wait())
}

public func testWriteServerSocketChannel() throws {
Expand Down

0 comments on commit 115a558

Please # to comment.