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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extension HTTPClientInternalTests {
("testWeNoticeRemoteClosuresEvenWhenConnectionIsIdleInPool", testWeNoticeRemoteClosuresEvenWhenConnectionIsIdleInPool),
("testWeTolerateConnectionsGoingAwayWhilstPoolIsShuttingDown", testWeTolerateConnectionsGoingAwayWhilstPoolIsShuttingDown),
("testRaceBetweenAsynchronousCloseAndChannelUsabilityDetection", testRaceBetweenAsynchronousCloseAndChannelUsabilityDetection),
("testResponseFutureIsOnCorrectEL", testResponseFutureIsOnCorrectEL),
("testUncleanCloseThrows", testUncleanCloseThrows),
]
}
}
46 changes: 46 additions & 0 deletions Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,50 @@ class HTTPClientInternalTests: XCTestCase {
}.wait()
XCTAssertTrue(connection2.channel.isActive)
}

func testResponseFutureIsOnCorrectEL() throws {
let group = getDefaultEventLoopGroup(numberOfThreads: 4)
defer {
XCTAssertNoThrow(try group.syncShutdownGracefully())
}
let client = HTTPClient(eventLoopGroupProvider: .shared(group))
let httpBin = HTTPBin()
defer {
XCTAssertNoThrow(try client.syncShutdown())
XCTAssertNoThrow(try httpBin.shutdown())
}

let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get")
var futures = [EventLoopFuture<HTTPClient.Response>]()
for _ in 1...100 {
let el = group.next()
let req1 = client.execute(request: request, eventLoop: .delegate(on: el))
let req2 = client.execute(request: request, eventLoop: .delegateAndChannel(on: el))
let req3 = client.execute(request: request, eventLoop: .init(.testOnly_exact(channelOn: el, delegateOn: el)))
XCTAssert(req1.eventLoop === el)
XCTAssert(req2.eventLoop === el)
XCTAssert(req3.eventLoop === el)
futures.append(contentsOf: [req1, req2, req3])
}
try EventLoopFuture<HTTPClient.Response>.andAllComplete(futures, on: group.next()).wait()
}

func testUncleanCloseThrows() {
let httpBin = HTTPBin()
defer {
XCTAssertNoThrow(try httpBin.shutdown())
}
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))

_ = httpClient.get(url: "http://localhost:\(httpBin.port)/wait")
do {
try httpClient.syncShutdown(requiresCleanClose: true)
XCTFail("There should be an error on shutdown")
} catch {
guard let clientError = error as? HTTPClientError, clientError == .uncleanShutdown else {
XCTFail("Unexpected shutdown error: \(error)")
return
}
}
}
}
2 changes: 0 additions & 2 deletions Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ extension HTTPClientTests {
("testWrongContentLengthForSSLUncleanShutdown", testWrongContentLengthForSSLUncleanShutdown),
("testWrongContentLengthWithIgnoreErrorForSSLUncleanShutdown", testWrongContentLengthWithIgnoreErrorForSSLUncleanShutdown),
("testEventLoopArgument", testEventLoopArgument),
("testResponseFutureIsOnCorrectEL", testResponseFutureIsOnCorrectEL),
("testDecompression", testDecompression),
("testDecompressionLimit", testDecompressionLimit),
("testLoopDetectionRedirectLimit", testLoopDetectionRedirectLimit),
Expand All @@ -73,7 +72,6 @@ extension HTTPClientTests {
("testSubsequentRequestsWorkWithServerAlternatingBetweenKeepAliveAndClose", testSubsequentRequestsWorkWithServerAlternatingBetweenKeepAliveAndClose),
("testStressGetHttps", testStressGetHttps),
("testStressGetHttpsSSLError", testStressGetHttpsSSLError),
("testUncleanCloseThrows", testUncleanCloseThrows),
("testFailingConnectionIsReleased", testFailingConnectionIsReleased),
("testResponseDelayGet", testResponseDelayGet),
("testIdleTimeoutNoReuse", testIdleTimeoutNoReuse),
Expand Down
Loading