You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_test.pony had grown to 2335 lines mixing integration tests, mock-server
unit tests, SSL negotiation tests, authentication protocol tests, and
cancel tests. Split into 5 new files organized by test concern:
- _test_session.pony: mock-server session behavior tests (junk messages,
unanswered queries, prepare shutdown, terminate, zero-row select)
- _test_ssl.pony: SSL negotiation unit tests + SSL integration tests
- _test_cancel.pony: cancel query unit tests with mock servers
- _test_auth.pony: SCRAM-SHA-256 + unsupported auth unit tests
- _test_md5.pony: MD5 authentication integration tests
_test.pony retains the Main test registry, _ConnectionTestConfiguration,
basic connect/auth integration tests, and shared notifies used across
files. All 80 unit tests pass. CLAUDE.md updated to reflect new layout.
Closes#96
Copy file name to clipboardExpand all lines: CLAUDE.md
+35-31Lines changed: 35 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,50 +130,49 @@ In `_RowsBuilder._field_to_type()`:
130
130
131
131
## Test Organization
132
132
133
-
Tests live in the main `postgres/` package (private test classes).
133
+
Tests live in the main `postgres/` package (private test classes), organized across multiple files by concern. The `Main` test actor in `_test.pony` is the single test registry that lists all tests.
134
134
135
-
**Unit tests**(no external dependencies):
136
-
-`_TestFrontendMessage*` — verify wire format of outgoing messages
137
-
-`_TestResponseParser*` — verify parsing of individual and sequential backend messages
135
+
**`_test.pony`**— Main test actor, `_ConnectionTestConfiguration` (shared env var helper), basic connection integration tests (Connect, ConnectFailure), basic auth integration tests (Authenticate, AuthenticateFailure), and shared notifies (`_ConnectTestNotify`, `_AuthenticateTestNotify`) reused by other test files.
-`_TestHandlingJunkMessages` — uses a local TCP listener that sends junk; verifies session shuts down
139
139
-`_TestUnansweredQueriesFailOnShutdown` — uses a local TCP listener that auto-auths but never responds to queries; verifies queued queries get `SessionClosed` failures
140
140
-`_TestPrepareShutdownDrainsPrepareQueue` — uses a local TCP listener that auto-auths but never becomes ready; verifies pending prepare operations get `SessionClosed` failures on shutdown
141
141
-`_TestTerminateSentOnClose` — mock server fully authenticates and becomes ready; verifies that closing the session sends a Terminate message ('X') to the server
142
+
-`_TestZeroRowSelectReturnsResultSet` — mock server sends RowDescription + CommandComplete("SELECT 0") with no DataRows; verifies ResultSet (not RowModifying) with zero rows
143
+
144
+
**`_test_ssl.pony`** — SSL negotiation unit tests (mock servers) and SSL integration tests:
142
145
-`_TestSSLNegotiationRefused` — mock server responds 'N' to SSLRequest; verifies `pg_session_connection_failed` fires
143
146
-`_TestSSLNegotiationJunkResponse` — mock server responds with junk byte to SSLRequest; verifies session shuts down
144
147
-`_TestSSLNegotiationSuccess` — mock server responds 'S', both sides upgrade to TLS, sends AuthOk+ReadyForQuery; verifies full SSL→auth flow
**`_test_cancel.pony`** — Cancel query unit tests (mock servers):
145
151
-`_TestCancelQueryInFlight` — mock server accepts two connections; first authenticates with BackendKeyData(pid, key) and receives query; second receives CancelRequest and verifies 16-byte format with correct magic number, pid, and key
146
152
-`_TestSSLCancelQueryInFlight` — same as `_TestCancelQueryInFlight` but with SSL on both connections; verifies that `_CancelSender` performs SSL negotiation before sending CancelRequest
147
-
-`_TestScramSha256MessageBuilders` — verifies SCRAM message builder functions produce correct output
148
-
-`_TestScramSha256ComputeProof` — verifies SCRAM proof computation against known test vectors
153
+
154
+
**`_test_auth.pony`** — Authentication protocol unit tests (mock servers):
149
155
-`_TestSCRAMAuthenticationSuccess` — mock server completes full SCRAM-SHA-256 handshake; verifies `pg_session_authenticated` fires
150
156
-`_TestSCRAMUnsupportedMechanism` — mock server offers only unsupported SASL mechanisms; verifies `pg_session_authentication_failed` with `UnsupportedAuthenticationMethod`
151
157
-`_TestSCRAMServerVerificationFailed` — mock server sends wrong signature in SASLFinal; verifies `pg_session_authentication_failed` with `ServerVerificationFailed`
152
158
-`_TestSCRAMErrorDuringAuth` — mock server sends ErrorResponse 28P01 during SCRAM exchange; verifies `pg_session_authentication_failed` with `InvalidPassword`
153
159
-`_TestUnsupportedAuthentication` — mock server sends unsupported auth type (cleartext password); verifies `pg_session_authentication_failed` with `UnsupportedAuthenticationMethod`
**`_test_response_parser.pony`** — Parser unit tests (`_TestResponseParser*`) + test message builder classes (`_Incoming*TestMessage`) that construct raw protocol bytes for mock servers across all test files.
170
+
171
+
**`_test_frontend_message.pony`** — Frontend message unit tests (`_TestFrontendMessage*`).
172
+
173
+
**`_test_equality.pony`** — Example-based and PonyCheck property tests for Field/Row/Rows equality.
174
+
175
+
**`_test_scram.pony`** — SCRAM-SHA-256 computation unit tests (`_TestScramSha256MessageBuilders`, `_TestScramSha256ComputeProof`).
177
176
178
177
Test helpers: `_ConnectionTestConfiguration` reads env vars with defaults. Several test message builder classes (`_Incoming*TestMessage`) construct raw protocol bytes for unit tests. Mock server tests use ports in the 7669–7682 range and 9667–9668. **Port 7680 is reserved by Windows** (Update Delivery Optimization) and will fail to bind on WSL2 — do not use it.
179
178
@@ -326,7 +325,7 @@ Can arrive between any other messages (must always handle):
326
325
## File Layout
327
326
328
327
```
329
-
postgres/ # Main package (35 files)
328
+
postgres/ # Main package (40 files)
330
329
session.pony # Session actor + state machine traits + query sub-state machine
331
330
database_connect_info.pony # DatabaseConnectInfo val class (user, password, database)
332
331
server_connect_info.pony # ServerConnectInfo val class (auth, host, service, ssl_mode)
@@ -356,7 +355,12 @@ postgres/ # Main package (35 files)
0 commit comments