Skip to content

Commit dcf76c1

Browse files
committed
Tidying up tests
- Added getDefaultEventLoopGroup() which will return TS or non TS EventLoopGroup based on environment variable ENABLE_TS_TESTS being set. - Added clientGroup and serverGroup EventLoopGroups to HTTPClientTests. - Stopped using TLS in Redirection tests as it is unnecessary and is hiding if TS version of code is working
1 parent 9500459 commit dcf76c1

File tree

3 files changed

+76
-64
lines changed

3 files changed

+76
-64
lines changed

Tests/AsyncHTTPClientTests/HTTPClientInternalTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class HTTPClientInternalTests: XCTestCase {
353353
}
354354
}
355355

356-
let group = MultiThreadedEventLoopGroup(numberOfThreads: 3)
356+
let group = getDefaultEventLoopGroup(numberOfThreads: 3)
357357
defer {
358358
XCTAssertNoThrow(try group.syncShutdownGracefully())
359359
}
@@ -546,7 +546,11 @@ class HTTPClientInternalTests: XCTestCase {
546546
}
547547

548548
let url = "http://127.0.0.1:\(server.localAddress!.port!)"
549-
let client = HTTPClient(eventLoopGroupProvider: .shared(group))
549+
let elg = getDefaultEventLoopGroup(numberOfThreads: 1)
550+
defer {
551+
XCTAssertNoThrow(try elg.syncShutdownGracefully())
552+
}
553+
let client = HTTPClient(eventLoopGroupProvider: .shared(elg))
550554
defer {
551555
XCTAssertNoThrow(try client.syncShutdown())
552556
}

Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ import NIOConcurrencyHelpers
1919
import NIOHTTP1
2020
import NIOHTTPCompression
2121
import NIOSSL
22+
import NIOTransportServices
23+
24+
func getDefaultEventLoopGroup(numberOfThreads: Int) -> EventLoopGroup {
25+
#if canImport(Network)
26+
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *),
27+
ProcessInfo.processInfo.environment["ENABLE_TS_TESTS"] != nil {
28+
return NIOTSEventLoopGroup(loopCount: numberOfThreads, defaultQoS: .default)
29+
}
30+
#endif
31+
return MultiThreadedEventLoopGroup(numberOfThreads: numberOfThreads)
32+
}
2233

2334
class TestHTTPDelegate: HTTPClientResponseDelegate {
2435
typealias Response = Void

0 commit comments

Comments
 (0)