From 5c268768890b062803a49f1358becc478f954265 Mon Sep 17 00:00:00 2001 From: Fabian Fett Date: Thu, 13 Jun 2024 18:54:18 +0200 Subject: [PATCH] Fix totally unnecessary `preconditionFailure` in `PSQLEventsHandler` (#481) --- Sources/PostgresNIO/New/PSQLEventsHandler.swift | 4 +--- Tests/PostgresNIOTests/New/PostgresConnectionTests.swift | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/PostgresNIO/New/PSQLEventsHandler.swift b/Sources/PostgresNIO/New/PSQLEventsHandler.swift index 2bf0d6d8..0f426f20 100644 --- a/Sources/PostgresNIO/New/PSQLEventsHandler.swift +++ b/Sources/PostgresNIO/New/PSQLEventsHandler.swift @@ -68,10 +68,8 @@ final class PSQLEventsHandler: ChannelInboundHandler { case .authenticated: break } - case TLSUserEvent.shutdownCompleted: - break default: - preconditionFailure() + context.fireUserInboundEventTriggered(event) } } diff --git a/Tests/PostgresNIOTests/New/PostgresConnectionTests.swift b/Tests/PostgresNIOTests/New/PostgresConnectionTests.swift index 34528f7e..209522dd 100644 --- a/Tests/PostgresNIOTests/New/PostgresConnectionTests.swift +++ b/Tests/PostgresNIOTests/New/PostgresConnectionTests.swift @@ -416,6 +416,15 @@ class PostgresConnectionTests: XCTestCase { } } + func testWeDontCrashOnUnexpectedChannelEvents() async throws { + let (connection, channel) = try await self.makeTestConnectionWithAsyncTestingChannel() + + enum MyEvent { + case pleaseDontCrash + } + channel.pipeline.fireUserInboundEventTriggered(MyEvent.pleaseDontCrash) + } + func testSerialExecutionOfSamePreparedStatement() async throws { let (connection, channel) = try await self.makeTestConnectionWithAsyncTestingChannel()