Skip to content

Commit

Permalink
Shutdown server gracefully in h2 transport tests (grpc#1996)
Browse files Browse the repository at this point in the history
Motivation:

The h2 transport tests cancel the task group running them when the test
has completed. Cancelling the server makes apple/swift-nio#2813
more likely to occur.

Modifications:

- Tell the server to stop listening and let the test stop gracefully

Result:

Fewer runtime issues
  • Loading branch information
glbrntt authored and clintonpi committed Jul 29, 2024
1 parent 9c33547 commit dddced2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Tests/GRPCHTTP2TransportTests/HTTP2TransportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class HTTP2TransportTests: XCTestCase {
) async throws {
for pair in transport {
try await withThrowingTaskGroup(of: Void.self) { group in
let address = try await self.runServer(
let (server, address) = try await self.runServer(
in: &group,
kind: pair.server,
enableControlService: enableControlService,
Expand Down Expand Up @@ -94,8 +94,8 @@ final class HTTP2TransportTests: XCTestCase {
XCTFail("Unexpected error: '\(error)' (\(pair))")
}

server.stopListening()
client.close()
group.cancelAll()
}
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ final class HTTP2TransportTests: XCTestCase {
kind: Transport.Kind,
enableControlService: Bool,
compression: CompressionAlgorithmSet
) async throws -> GRPCHTTP2Core.SocketAddress {
) async throws -> (GRPCServer, GRPCHTTP2Core.SocketAddress) {
let services = enableControlService ? [ControlService()] : []

switch kind {
Expand All @@ -156,7 +156,8 @@ final class HTTP2TransportTests: XCTestCase {
try await server.run()
}

return try await transport.listeningAddress
let address = try await transport.listeningAddress
return (server, address)

case .niots:
#if canImport(Network)
Expand All @@ -172,7 +173,8 @@ final class HTTP2TransportTests: XCTestCase {
try await server.run()
}

return try await transport.listeningAddress
let address = try await transport.listeningAddress
return (server, address)
#else
throw XCTSkip("Transport not supported on this platform")
#endif
Expand Down

0 comments on commit dddced2

Please sign in to comment.