Skip to content

Commit 5c81c71

Browse files
committed
fix tests on linux
we needed an event loop group which outlives the http client
1 parent 5b4f104 commit 5c81c71

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: Tests/AsyncHTTPClientTests/HTTP2ClientTests.swift

+11-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import NIOSSL
2424
import XCTest
2525

2626
class HTTP2ClientTests: XCTestCase {
27-
func makeDefaultHTTPClient() -> HTTPClient {
27+
func makeDefaultHTTPClient(
28+
eventLoopGroupProvider: HTTPClient.EventLoopGroupProvider = .createNew
29+
) -> HTTPClient {
2830
var tlsConfig = TLSConfiguration.makeClientConfiguration()
2931
tlsConfig.certificateVerification = .none
3032
return HTTPClient(
31-
eventLoopGroupProvider: .createNew,
33+
eventLoopGroupProvider: eventLoopGroupProvider,
3234
configuration: HTTPClient.Configuration(
3335
tlsConfiguration: tlsConfig,
3436
httpVersion: .automatic
@@ -38,9 +40,10 @@ class HTTP2ClientTests: XCTestCase {
3840
}
3941

4042
func makeClientWithActiveHTTP2Connection<RequestHandler>(
41-
to bin: HTTPBin<RequestHandler>
43+
to bin: HTTPBin<RequestHandler>,
44+
eventLoopGroupProvider: HTTPClient.EventLoopGroupProvider = .createNew
4245
) -> HTTPClient {
43-
let client = self.makeDefaultHTTPClient()
46+
let client = self.makeDefaultHTTPClient(eventLoopGroupProvider: eventLoopGroupProvider)
4447
var response: HTTPClient.Response?
4548
XCTAssertNoThrow(response = try client.get(url: "https://localhost:\(bin.port)/get").wait())
4649
XCTAssertEqual(.ok, response?.status)
@@ -202,7 +205,9 @@ class HTTP2ClientTests: XCTestCase {
202205
func testUncleanShutdownCancelsExecutingAndQueuedTasks() {
203206
let bin = HTTPBin(.http2(compress: false))
204207
defer { XCTAssertNoThrow(try bin.shutdown()) }
205-
let client = self.makeClientWithActiveHTTP2Connection(to: bin)
208+
let clientGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
209+
defer { XCTAssertNoThrow(try clientGroup.syncShutdownGracefully()) }
210+
let client = self.makeClientWithActiveHTTP2Connection(to: bin, eventLoopGroupProvider: .shared(clientGroup))
206211

207212
// start 20 requests which are guaranteed to never get any response
208213
// 10 of them will executed and the other 10 will be queued
@@ -215,7 +220,7 @@ class HTTP2ClientTests: XCTestCase {
215220

216221
var results: [Result<HTTPClient.Response, Error>] = []
217222
XCTAssertNoThrow(results = try EventLoopFuture
218-
.whenAllComplete(responses, on: client.eventLoopGroup.next())
223+
.whenAllComplete(responses, on: clientGroup.next())
219224
.timeout(after: .seconds(2))
220225
.wait())
221226

0 commit comments

Comments
 (0)