Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/NIO/Embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ class EmbeddedChannelCore: ChannelCore {
return
}
isOpen = false
isActive = false
promise?.succeed(result: ())

// As we called register() in the constructor of EmbeddedChannel we also need to ensure we call unregistered here.
isActive = false
pipeline.fireChannelInactive0()
pipeline.fireChannelUnregistered0()

Expand All @@ -194,8 +194,8 @@ class EmbeddedChannelCore: ChannelCore {
}

func connect0(to address: SocketAddress, promise: EventLoopPromise<Void>?) {
promise?.succeed(result: ())
isActive = true
promise?.succeed(result: ())
pipeline.fireChannelActive0()
}

Expand Down
1 change: 1 addition & 0 deletions Tests/NIOTests/EmbeddedChannelTest+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extension EmbeddedChannelTest {
("testEmbeddedLifecycle", testEmbeddedLifecycle),
("testEmbeddedChannelAndPipelineAndChannelCoreShareTheEventLoop", testEmbeddedChannelAndPipelineAndChannelCoreShareTheEventLoop),
("testSendingIncorrectDataOnEmbeddedChannel", testSendingIncorrectDataOnEmbeddedChannel),
("testActiveWhenConnectPromiseFiresAndInactiveWhenClosePromiseFires", testActiveWhenConnectPromiseFiresAndInactiveWhenClosePromiseFires),
]
}
}
Expand Down
19 changes: 19 additions & 0 deletions Tests/NIOTests/EmbeddedChannelTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,23 @@ class EmbeddedChannelTest: XCTestCase {

XCTAssertFalse(try channel.finish())
}

func testActiveWhenConnectPromiseFiresAndInactiveWhenClosePromiseFires() throws {
let channel = EmbeddedChannel()
XCTAssertFalse(channel.isActive)
let connectPromise: EventLoopPromise<Void> = channel.eventLoop.newPromise()
connectPromise.futureResult.whenComplete {
XCTAssertTrue(channel.isActive)
}
channel.connect(to: try SocketAddress(ipAddress: "127.0.0.1", port: 0), promise: connectPromise)
try connectPromise.futureResult.wait()

let closePromise: EventLoopPromise<Void> = channel.eventLoop.newPromise()
closePromise.futureResult.whenComplete {
XCTAssertFalse(channel.isActive)
}

channel.close(promise: closePromise)
try closePromise.futureResult.wait()
}
}