Skip to content

Commit e341244

Browse files
committed
Updated tests
- Shutdown ELG in testUploadStreamingBackpressure - Added isTestingNIOTS() - Added testCorrectEventLoopGroup
1 parent 77986b5 commit e341244

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
@@ -386,7 +386,7 @@ class HTTPClientTests: XCTestCase {
386386
func testProxyTLS() throws {
387387
XCTFail("Disabled test as it crashes");
388388
return
389-
389+
390390
let httpBin = HTTPBin(simulateProxy: .tls)
391391
let httpClient = HTTPClient(
392392
eventLoopGroupProvider: .shared(self.clientGroup),
@@ -1089,11 +1089,9 @@ class HTTPClientTests: XCTestCase {
10891089
}
10901090

10911091
func testStressGetClose() throws {
1092-
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
1093-
guard !(self.clientGroup is NIOTSEventLoopGroup) else {
1094-
XCTFail("Disabled test as it crashes");
1095-
return
1096-
}
1092+
guard !isTestingNIOTS() else {
1093+
XCTFail("Disabled test as it crashes");
1094+
return
10971095
}
10981096
let httpBin = HTTPBin(ssl: false)
10991097
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup),
@@ -1667,15 +1665,29 @@ class HTTPClientTests: XCTestCase {
16671665
}
16681666

16691667
func testAsyncShutdown() {
1670-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
1671-
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
1672-
let promise = eventLoopGroup.next().makePromise(of: Void.self)
1673-
eventLoopGroup.next().execute {
1668+
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup))
1669+
let promise = self.clientGroup.next().makePromise(of: Void.self)
1670+
self.clientGroup.next().execute {
16741671
httpClient.shutdown(queue: DispatchQueue(label: "testAsyncShutdown")) { error in
16751672
XCTAssertNil(error)
16761673
promise.succeed(())
16771674
}
16781675
}
16791676
XCTAssertNoThrow(try promise.futureResult.wait())
16801677
}
1678+
1679+
1680+
func testCorrectEventLoopGroup() {
1681+
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
1682+
defer {
1683+
XCTAssertNoThrow(try httpClient.syncShutdown())
1684+
}
1685+
#if canImport(Network)
1686+
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) {
1687+
XCTAssertTrue(httpClient.eventLoopGroup is NIOTSEventLoopGroup)
1688+
return
1689+
}
1690+
#endif
1691+
XCTAssertTrue(httpClient.eventLoopGroup is MultiThreadedEventLoopGroup)
1692+
}
16811693
}

0 commit comments

Comments
 (0)