-
Notifications
You must be signed in to change notification settings - Fork 133
All internal connection flow should be executed when shutting down #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e9e852c
0aeb535
498945b
3c7d3bf
d3240aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1391,6 +1391,168 @@ class ConnectionPoolTests: XCTestCase { | |
} | ||
} | ||
|
||
// MARK: - Shutdown tests | ||
|
||
func testShutdownOnPendingAndSuccess() { | ||
var state = HTTP1ConnectionProvider.ConnectionsState(eventLoop: self.eventLoop) | ||
|
||
XCTAssertTrue(state.enqueue()) | ||
|
||
let connectionPromise = self.eventLoop.makePromise(of: Connection.self) | ||
let setupPromise = self.eventLoop.makePromise(of: Void.self) | ||
let waiter = HTTP1ConnectionProvider.Waiter(promise: connectionPromise, setupComplete: setupPromise.futureResult, preference: .indifferent) | ||
var action = state.acquire(waiter: waiter) | ||
|
||
switch action { | ||
|
||
case .create: | ||
// expected | ||
break | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
|
||
let snapshot = state.testsOnly_getInternalState() | ||
XCTAssertEqual(snapshot.openedConnectionsCount, 1) | ||
|
||
if let (waiters, available, leased, clean) = state.close() { | ||
XCTAssertTrue(waiters.isEmpty) | ||
XCTAssertTrue(available.isEmpty) | ||
XCTAssertTrue(leased.isEmpty) | ||
XCTAssertFalse(clean) | ||
} else { | ||
XCTFail("Expecting snapshot") | ||
} | ||
|
||
let connection = Connection(channel: EmbeddedChannel(), provider: self.http1ConnectionProvider) | ||
|
||
action = state.offer(connection: connection) | ||
switch action { | ||
case .closeAnd(_, let next): | ||
|
||
switch next { | ||
case .closeProvider: | ||
// expected | ||
break | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
|
||
connectionPromise.fail(TempError()) | ||
setupPromise.succeed(()) | ||
} | ||
|
||
func testShutdownOnPendingAndError() { | ||
var state = HTTP1ConnectionProvider.ConnectionsState(eventLoop: self.eventLoop) | ||
|
||
XCTAssertTrue(state.enqueue()) | ||
|
||
let connectionPromise = self.eventLoop.makePromise(of: Connection.self) | ||
let setupPromise = self.eventLoop.makePromise(of: Void.self) | ||
let waiter = HTTP1ConnectionProvider.Waiter(promise: connectionPromise, setupComplete: setupPromise.futureResult, preference: .indifferent) | ||
var action = state.acquire(waiter: waiter) | ||
|
||
switch action { | ||
|
||
case .create: | ||
// expected | ||
break | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
|
||
let snapshot = state.testsOnly_getInternalState() | ||
XCTAssertEqual(snapshot.openedConnectionsCount, 1) | ||
|
||
if let (waiters, available, leased, clean) = state.close() { | ||
XCTAssertTrue(waiters.isEmpty) | ||
XCTAssertTrue(available.isEmpty) | ||
XCTAssertTrue(leased.isEmpty) | ||
XCTAssertFalse(clean) | ||
} else { | ||
XCTFail("Expecting snapshot") | ||
} | ||
|
||
action = state.connectFailed() | ||
switch action { | ||
|
||
case .closeProvider: | ||
// expected | ||
break | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
|
||
connectionPromise.fail(TempError()) | ||
setupPromise.succeed(()) | ||
} | ||
|
||
func testShutdownTimeout() { | ||
var state = HTTP1ConnectionProvider.ConnectionsState(eventLoop: self.eventLoop) | ||
|
||
var snapshot = self.http1ConnectionProvider.state.testsOnly_getInternalState() | ||
|
||
let connection = Connection(channel: EmbeddedChannel(), provider: self.http1ConnectionProvider) | ||
snapshot.availableConnections.append(connection) | ||
snapshot.openedConnectionsCount = 1 | ||
|
||
state.testsOnly_setInternalState(snapshot) | ||
|
||
if let (waiters, available, leased, clean) = state.close() { | ||
XCTAssertTrue(waiters.isEmpty) | ||
XCTAssertFalse(available.isEmpty) | ||
XCTAssertTrue(leased.isEmpty) | ||
XCTAssertTrue(clean) | ||
} else { | ||
XCTFail("Expecting snapshot") | ||
} | ||
|
||
let action = state.timeout(connection: connection) | ||
switch action { | ||
case .closeAnd(_, let next): | ||
switch next { | ||
case .closeProvider: | ||
// expected | ||
break | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
} | ||
|
||
func testShutdownRemoteClosed() { | ||
var state = HTTP1ConnectionProvider.ConnectionsState(eventLoop: self.eventLoop) | ||
|
||
var snapshot = self.http1ConnectionProvider.state.testsOnly_getInternalState() | ||
|
||
let connection = Connection(channel: EmbeddedChannel(), provider: self.http1ConnectionProvider) | ||
snapshot.availableConnections.append(connection) | ||
snapshot.openedConnectionsCount = 1 | ||
|
||
state.testsOnly_setInternalState(snapshot) | ||
|
||
if let (waiters, available, leased, clean) = state.close() { | ||
XCTAssertTrue(waiters.isEmpty) | ||
XCTAssertFalse(available.isEmpty) | ||
XCTAssertTrue(leased.isEmpty) | ||
XCTAssertTrue(clean) | ||
} else { | ||
XCTFail("Expecting snapshot") | ||
} | ||
|
||
let action = state.remoteClosed(connection: connection) | ||
switch action { | ||
case .closeProvider: | ||
// expected | ||
break | ||
default: | ||
XCTFail("Unexpected action: \(action)") | ||
} | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
override func setUp() { | ||
XCTAssertNil(self.eventLoop) | ||
XCTAssertNil(self.http1ConnectionProvider) | ||
|
Uh oh!
There was an error while loading. Please reload this page.