Skip to content

Commit

Permalink
Add test to ensure channel is shutdown on TLS dangling open
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Jul 4, 2024
1 parent 64033e6 commit 0df0711
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Tests/HummingbirdCoreTests/TLSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import HummingbirdCore
import HummingbirdTesting
import HummingbirdTLS
import Logging
import NIOConcurrencyHelpers
import NIOCore
import NIOPosix
import NIOSSL
Expand All @@ -39,4 +40,24 @@ class HummingBirdTLSTests: XCTestCase {
XCTAssertEqual(body.readString(length: body.readableBytes), "Hello")
}
}

func testGracefulShutdown() async throws {
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 2)
defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) }
let clientChannel: NIOLockedValueBox<Channel?> = .init(nil)
try await testServer(
responder: helloResponder,
httpChannelSetup: .tls(tlsConfiguration: getServerTLSConfiguration()),
configuration: .init(address: .hostname(port: 0), serverName: testServerName),
eventLoopGroup: eventLoopGroup,
logger: Logger(label: "Hummingbird")
) { port in
let channel = try await ClientBootstrap(group: eventLoopGroup)
.connect(host: "127.0.0.1", port: port).get()
clientChannel.withLockedValue { $0 = channel }
}
// test channel has been closed
let channel = try clientChannel.withLockedValue { try XCTUnwrap($0) }
try await channel.closeFuture.get()
}
}

0 comments on commit 0df0711

Please sign in to comment.