Refactored the startup reply in the fake PostgreSQL server in the Persistence tests target.

This commit is contained in:
2026-08-05 01:30:52 +02:00
parent f8a263168e
commit 52f092a4d7
@@ -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