Skip to content

Commit b1bb7ae

Browse files
authored
make public API tests not use @testable again (#216)
Motivation: AHC's tests were split in HTTPClientTests (which only use the public API) and HTTPClientInternalTests (which can use `internal` API by using `@testable`). At some point, the public API tests had `@testable` added to the AHC import which breaks this idea. Modification: Restore the intent by removing `@testable` and moving the 2 tests that needed it over. Result: Cleaner test suite.
1 parent 8adfdb9 commit b1bb7ae

File tree

4 files changed

+108
-108
lines changed

4 files changed

+108
-108
lines changed

Tests/AsyncHTTPClientTests/HTTPClientInternalTests+XCTest.swift

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extension HTTPClientInternalTests {
3737
("testWeNoticeRemoteClosuresEvenWhenConnectionIsIdleInPool", testWeNoticeRemoteClosuresEvenWhenConnectionIsIdleInPool),
3838
("testWeTolerateConnectionsGoingAwayWhilstPoolIsShuttingDown", testWeTolerateConnectionsGoingAwayWhilstPoolIsShuttingDown),
3939
("testRaceBetweenAsynchronousCloseAndChannelUsabilityDetection", testRaceBetweenAsynchronousCloseAndChannelUsabilityDetection),
40+
("testResponseFutureIsOnCorrectEL", testResponseFutureIsOnCorrectEL),
41+
("testUncleanCloseThrows", testUncleanCloseThrows),
4042
]
4143
}
4244
}

Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift

+46
Original file line numberDiff line numberDiff line change
@@ -760,4 +760,50 @@ class HTTPClientInternalTests: XCTestCase {
760760
}.wait()
761761
XCTAssertTrue(connection2.channel.isActive)
762762
}
763+
764+
func testResponseFutureIsOnCorrectEL() throws {
765+
let group = getDefaultEventLoopGroup(numberOfThreads: 4)
766+
defer {
767+
XCTAssertNoThrow(try group.syncShutdownGracefully())
768+
}
769+
let client = HTTPClient(eventLoopGroupProvider: .shared(group))
770+
let httpBin = HTTPBin()
771+
defer {
772+
XCTAssertNoThrow(try client.syncShutdown())
773+
XCTAssertNoThrow(try httpBin.shutdown())
774+
}
775+
776+
let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get")
777+
var futures = [EventLoopFuture<HTTPClient.Response>]()
778+
for _ in 1...100 {
779+
let el = group.next()
780+
let req1 = client.execute(request: request, eventLoop: .delegate(on: el))
781+
let req2 = client.execute(request: request, eventLoop: .delegateAndChannel(on: el))
782+
let req3 = client.execute(request: request, eventLoop: .init(.testOnly_exact(channelOn: el, delegateOn: el)))
783+
XCTAssert(req1.eventLoop === el)
784+
XCTAssert(req2.eventLoop === el)
785+
XCTAssert(req3.eventLoop === el)
786+
futures.append(contentsOf: [req1, req2, req3])
787+
}
788+
try EventLoopFuture<HTTPClient.Response>.andAllComplete(futures, on: group.next()).wait()
789+
}
790+
791+
func testUncleanCloseThrows() {
792+
let httpBin = HTTPBin()
793+
defer {
794+
XCTAssertNoThrow(try httpBin.shutdown())
795+
}
796+
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
797+
798+
_ = httpClient.get(url: "http://localhost:\(httpBin.port)/wait")
799+
do {
800+
try httpClient.syncShutdown(requiresCleanClose: true)
801+
XCTFail("There should be an error on shutdown")
802+
} catch {
803+
guard let clientError = error as? HTTPClientError, clientError == .uncleanShutdown else {
804+
XCTFail("Unexpected shutdown error: \(error)")
805+
return
806+
}
807+
}
808+
}
763809
}

Tests/AsyncHTTPClientTests/HTTPClientTests+XCTest.swift

-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ extension HTTPClientTests {
6060
("testWrongContentLengthForSSLUncleanShutdown", testWrongContentLengthForSSLUncleanShutdown),
6161
("testWrongContentLengthWithIgnoreErrorForSSLUncleanShutdown", testWrongContentLengthWithIgnoreErrorForSSLUncleanShutdown),
6262
("testEventLoopArgument", testEventLoopArgument),
63-
("testResponseFutureIsOnCorrectEL", testResponseFutureIsOnCorrectEL),
6463
("testDecompression", testDecompression),
6564
("testDecompressionLimit", testDecompressionLimit),
6665
("testLoopDetectionRedirectLimit", testLoopDetectionRedirectLimit),
@@ -73,7 +72,6 @@ extension HTTPClientTests {
7372
("testSubsequentRequestsWorkWithServerAlternatingBetweenKeepAliveAndClose", testSubsequentRequestsWorkWithServerAlternatingBetweenKeepAliveAndClose),
7473
("testStressGetHttps", testStressGetHttps),
7574
("testStressGetHttpsSSLError", testStressGetHttpsSSLError),
76-
("testUncleanCloseThrows", testUncleanCloseThrows),
7775
("testFailingConnectionIsReleased", testFailingConnectionIsReleased),
7876
("testResponseDelayGet", testResponseDelayGet),
7977
("testIdleTimeoutNoReuse", testIdleTimeoutNoReuse),

0 commit comments

Comments
 (0)