diff --git a/Packages/Persistence/Tests/Utils/Fakes/PlaintextPostgresServer.swift b/Packages/Persistence/Tests/Utils/Fakes/PlaintextPostgresServer.swift index d19762a..0df114d 100644 --- a/Packages/Persistence/Tests/Utils/Fakes/PlaintextPostgresServer.swift +++ b/Packages/Persistence/Tests/Utils/Fakes/PlaintextPostgresServer.swift @@ -99,7 +99,7 @@ private extension PlaintextPostgresServer { context: ChannelHandlerContext, data: NIOAny ) { - var buffer = unwrapInboundIn(data) + let buffer = unwrapInboundIn(data) switch state { case .awaitingSSLRequest: @@ -107,13 +107,7 @@ private extension PlaintextPostgresServer { // 'N', while a direct startup message (a client connecting with TLS disabled) is // answered straight away. guard buffer.getInteger(at: buffer.readerIndex + 4, as: Int32.self) == Self.sslRequestCode else { - state = .established - - context.writeAndFlush( - wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)), - promise: nil - ) - + completeStartup(context: context) return } @@ -128,17 +122,22 @@ private extension PlaintextPostgresServer { promise: nil ) case .awaitingStartup: - state = .established - - context.writeAndFlush( - wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)), - promise: nil - ) + completeStartup(context: context) case .established: context.close(promise: nil) } } + /// Answers a startup message and marks the connection established. + private func completeStartup(context: ChannelHandlerContext) { + state = .established + + context.writeAndFlush( + wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)), + promise: nil + ) + } + // MARK: Helpers /// The reply completing a plaintext startup: `AuthenticationOk`, `BackendKeyData`, and