Skip to content

Commit a7815d1

Browse files
committed
Updated tests
- Shutdown ELG in testUploadStreamingBackpressure - Added isTestingNIOTS() - Added testCorrectEventLoopGroup
1 parent 6451389 commit a7815d1

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class HTTPClientInternalTests: XCTestCase {
239239
defer {
240240
XCTAssertNoThrow(try httpClient.syncShutdown(requiresCleanClose: true))
241241
XCTAssertNoThrow(try httpBin.shutdown())
242+
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
242243
}
243244

244245
let request = try Request(url: "http://localhost:\(httpBin.port)/custom")

Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ import NIOHTTPCompression
2121
import NIOSSL
2222
import NIOTransportServices
2323

24+
/// Are we testing NIO Transport services
25+
func isTestingNIOTS() -> Bool {
26+
return ProcessInfo.processInfo.environment["ENABLE_TS_TESTS"] == "true"
27+
}
28+
2429
func getDefaultEventLoopGroup(numberOfThreads: Int) -> EventLoopGroup {
2530
#if canImport(Network)
2631
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *),
27-
ProcessInfo.processInfo.environment["ENABLE_TS_TESTS"] == "true" {
32+
isTestingNIOTS() {
2833
return NIOTSEventLoopGroup(loopCount: numberOfThreads, defaultQoS: .default)
2934
}
3035
#endif

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class HTTPClientTests: XCTestCase {
398398
func testProxyTLS() throws {
399399
XCTFail("Disabled test as it crashes");
400400
return
401-
401+
402402
let httpBin = HTTPBin(simulateProxy: .tls)
403403
let httpClient = HTTPClient(
404404
eventLoopGroupProvider: .shared(self.clientGroup),
@@ -1101,11 +1101,9 @@ class HTTPClientTests: XCTestCase {
11011101
}
11021102

11031103
func testStressGetClose() throws {
1104-
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
1105-
guard !(self.clientGroup is NIOTSEventLoopGroup) else {
1106-
XCTFail("Disabled test as it crashes");
1107-
return
1108-
}
1104+
guard !isTestingNIOTS() else {
1105+
XCTFail("Disabled test as it crashes");
1106+
return
11091107
}
11101108
let httpBin = HTTPBin(ssl: false)
11111109
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
@@ -1679,15 +1677,29 @@ class HTTPClientTests: XCTestCase {
16791677
}
16801678

16811679
func testAsyncShutdown() {
1682-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
1683-
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
1684-
let promise = eventLoopGroup.next().makePromise(of: Void.self)
1685-
eventLoopGroup.next().execute {
1680+
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
1681+
let promise = self.clientGroup.next().makePromise(of: Void.self)
1682+
self.clientGroup.next().execute {
16861683
httpClient.shutdown(queue: DispatchQueue(label: "testAsyncShutdown")) { error in
16871684
XCTAssertNil(error)
16881685
promise.succeed(())
16891686
}
16901687
}
16911688
XCTAssertNoThrow(try promise.futureResult.wait())
16921689
}
1690+
1691+
1692+
func testCorrectEventLoopGroup() {
1693+
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
1694+
defer {
1695+
XCTAssertNoThrow(try httpClient.syncShutdown())
1696+
}
1697+
#if canImport(Network)
1698+
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
1699+
XCTAssertTrue(httpClient.eventLoopGroup is NIOTSEventLoopGroup)
1700+
return
1701+
}
1702+
#endif
1703+
XCTAssertTrue(httpClient.eventLoopGroup is MultiThreadedEventLoopGroup)
1704+
}
16931705
}

0 commit comments

Comments
 (0)