Refactored the startup reply in the fake PostgreSQL server in the Persistence tests target.
This commit is contained in:
@@ -99,7 +99,7 @@ private extension PlaintextPostgresServer {
|
|||||||
context: ChannelHandlerContext,
|
context: ChannelHandlerContext,
|
||||||
data: NIOAny
|
data: NIOAny
|
||||||
) {
|
) {
|
||||||
var buffer = unwrapInboundIn(data)
|
let buffer = unwrapInboundIn(data)
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case .awaitingSSLRequest:
|
case .awaitingSSLRequest:
|
||||||
@@ -107,13 +107,7 @@ private extension PlaintextPostgresServer {
|
|||||||
// 'N', while a direct startup message (a client connecting with TLS disabled) is
|
// 'N', while a direct startup message (a client connecting with TLS disabled) is
|
||||||
// answered straight away.
|
// answered straight away.
|
||||||
guard buffer.getInteger(at: buffer.readerIndex + 4, as: Int32.self) == Self.sslRequestCode else {
|
guard buffer.getInteger(at: buffer.readerIndex + 4, as: Int32.self) == Self.sslRequestCode else {
|
||||||
state = .established
|
completeStartup(context: context)
|
||||||
|
|
||||||
context.writeAndFlush(
|
|
||||||
wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)),
|
|
||||||
promise: nil
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,17 +122,22 @@ private extension PlaintextPostgresServer {
|
|||||||
promise: nil
|
promise: nil
|
||||||
)
|
)
|
||||||
case .awaitingStartup:
|
case .awaitingStartup:
|
||||||
state = .established
|
completeStartup(context: context)
|
||||||
|
|
||||||
context.writeAndFlush(
|
|
||||||
wrapOutboundOut(Self.startupResponse(allocator: context.channel.allocator)),
|
|
||||||
promise: nil
|
|
||||||
)
|
|
||||||
case .established:
|
case .established:
|
||||||
context.close(promise: nil)
|
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
|
// MARK: Helpers
|
||||||
|
|
||||||
/// The reply completing a plaintext startup: `AuthenticationOk`, `BackendKeyData`, and
|
/// The reply completing a plaintext startup: `AuthenticationOk`, `BackendKeyData`, and
|
||||||
|
|||||||
Reference in New Issue
Block a user