Skip to content

Commit 3fe8b39

Browse files
committed
Reorganize tests into logical files by concern
_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
1 parent 099eca0 commit 3fe8b39

File tree

7 files changed

+2113
-2099
lines changed

7 files changed

+2113
-2099
lines changed

CLAUDE.md

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -130,50 +130,49 @@ In `_RowsBuilder._field_to_type()`:
130130

131131
## Test Organization
132132

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.
134134

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.
136+
137+
**`_test_session.pony`**Mock-server-based session behavior tests:
138138
- `_TestHandlingJunkMessages` — uses a local TCP listener that sends junk; verifies session shuts down
139139
- `_TestUnansweredQueriesFailOnShutdown` — uses a local TCP listener that auto-auths but never responds to queries; verifies queued queries get `SessionClosed` failures
140140
- `_TestPrepareShutdownDrainsPrepareQueue` — uses a local TCP listener that auto-auths but never becomes ready; verifies pending prepare operations get `SessionClosed` failures on shutdown
141141
- `_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:
142145
- `_TestSSLNegotiationRefused` — mock server responds 'N' to SSLRequest; verifies `pg_session_connection_failed` fires
143146
- `_TestSSLNegotiationJunkResponse` — mock server responds with junk byte to SSLRequest; verifies session shuts down
144147
- `_TestSSLNegotiationSuccess` — mock server responds 'S', both sides upgrade to TLS, sends AuthOk+ReadyForQuery; verifies full SSL→auth flow
148+
- SSL integration tests: SSL/Connect, SSL/Authenticate, SSL/Query, SSL/Refused
149+
150+
**`_test_cancel.pony`** — Cancel query unit tests (mock servers):
145151
- `_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
146152
- `_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):
149155
- `_TestSCRAMAuthenticationSuccess` — mock server completes full SCRAM-SHA-256 handshake; verifies `pg_session_authenticated` fires
150156
- `_TestSCRAMUnsupportedMechanism` — mock server offers only unsupported SASL mechanisms; verifies `pg_session_authentication_failed` with `UnsupportedAuthenticationMethod`
151157
- `_TestSCRAMServerVerificationFailed` — mock server sends wrong signature in SASLFinal; verifies `pg_session_authentication_failed` with `ServerVerificationFailed`
152158
- `_TestSCRAMErrorDuringAuth` — mock server sends ErrorResponse 28P01 during SCRAM exchange; verifies `pg_session_authentication_failed` with `InvalidPassword`
153159
- `_TestUnsupportedAuthentication` — mock server sends unsupported auth type (cleartext password); verifies `pg_session_authentication_failed` with `UnsupportedAuthenticationMethod`
154-
- `_TestResponseParserParameterStatusSkipped` — verify ParameterStatus ('S') returns `_SkippedMessage`
155-
- `_TestResponseParserNoticeResponseSkipped` — verify NoticeResponse ('N') returns `_SkippedMessage`
156-
- `_TestResponseParserNotificationResponseSkipped` — verify NotificationResponse ('A') returns `_SkippedMessage`
157-
- `_TestResponseParserMultipleMessagesSkippedFirst` — chain all three skipped types + AuthenticationOk to verify buffer advancement
158-
- `_TestField*Equality*` / `_TestFieldInequality` — example-based reflexive, structural, symmetric equality and inequality tests for Field
159-
- `_TestRowEquality` / `_TestRowInequality` — example-based equality and inequality tests for Row
160-
- `_TestRowsEquality` / `_TestRowsInequality` — example-based equality and inequality tests for Rows
161-
- `_TestField*Property` — PonyCheck property tests for Field reflexive, structural, and symmetric equality
162-
- `_TestRowReflexiveProperty` / `_TestRowsReflexiveProperty` — PonyCheck property tests for Row/Rows reflexive equality
163-
164-
**Integration tests** (require PostgreSQL, names prefixed `integration/`):
165-
- Connect, ConnectFailure, Authenticate, AuthenticateFailure
166-
- Query/Results, Query/AfterAuthenticationFailure, Query/AfterConnectionFailure, Query/AfterSessionHasBeenClosed
167-
- Query/OfNonExistentTable, Query/CreateAndDropTable, Query/InsertAndDelete, Query/EmptyQuery
168-
- PreparedQuery/Results, PreparedQuery/NullParam, PreparedQuery/OfNonExistentTable
169-
- PreparedQuery/InsertAndDelete, PreparedQuery/MixedWithSimple
170-
- PreparedStatement/Prepare, PreparedStatement/PrepareAndExecute, PreparedStatement/PrepareAndExecuteMultiple
171-
- PreparedStatement/PrepareAndClose, PreparedStatement/PrepareFails, PreparedStatement/PrepareAfterClose
172-
- PreparedStatement/CloseNonexistent, PreparedStatement/PrepareDuplicateName
173-
- PreparedStatement/MixedWithSimpleAndPrepared
174-
- Cancel/Query
175-
- SSL/Connect, SSL/Authenticate, SSL/Query, SSL/Refused, SSL/Cancel
176-
- MD5/Authenticate, MD5/AuthenticateFailure, MD5/QueryResults
160+
161+
**`_test_md5.pony`** — MD5 integration tests: MD5/Authenticate, MD5/AuthenticateFailure, MD5/QueryResults
162+
163+
**`_test_query.pony`** — Query integration tests:
164+
- Simple query: Query/Results, Query/AfterAuthenticationFailure, Query/AfterConnectionFailure, Query/AfterSessionHasBeenClosed, Query/OfNonExistentTable, Query/CreateAndDropTable, Query/InsertAndDelete, Query/EmptyQuery, ZeroRowSelect, MultiStatementMixedResults
165+
- Prepared query: PreparedQuery/Results, PreparedQuery/NullParam, PreparedQuery/OfNonExistentTable, PreparedQuery/InsertAndDelete, PreparedQuery/MixedWithSimple
166+
- Named prepared statements: PreparedStatement/Prepare, PreparedStatement/PrepareAndExecute, PreparedStatement/PrepareAndExecuteMultiple, PreparedStatement/PrepareAndClose, PreparedStatement/PrepareFails, PreparedStatement/PrepareAfterClose, PreparedStatement/CloseNonexistent, PreparedStatement/PrepareDuplicateName, PreparedStatement/MixedWithSimpleAndPrepared
167+
- Cancel integration: Cancel/Query, SSL/Cancel
168+
169+
**`_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`).
177176

178177
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.
179178

@@ -326,7 +325,7 @@ Can arrive between any other messages (must always handle):
326325
## File Layout
327326

328327
```
329-
postgres/ # Main package (35 files)
328+
postgres/ # Main package (40 files)
330329
session.pony # Session actor + state machine traits + query sub-state machine
331330
database_connect_info.pony # DatabaseConnectInfo val class (user, password, database)
332331
server_connect_info.pony # ServerConnectInfo val class (auth, host, service, ssl_mode)
@@ -356,7 +355,12 @@ postgres/ # Main package (35 files)
356355
_md5_password.pony # MD5 password construction
357356
_scram_sha256.pony # SCRAM-SHA-256 computation primitive
358357
_mort.pony # Panic primitives
359-
_test.pony # Main test actor + integration tests + SSL/SCRAM negotiation tests
358+
_test.pony # Main test actor + shared test config + basic connect/auth integration tests
359+
_test_session.pony # Mock-server session behavior tests (junk, shutdown, terminate, zero-row)
360+
_test_ssl.pony # SSL negotiation unit tests + SSL integration tests
361+
_test_cancel.pony # Cancel query unit tests (mock servers)
362+
_test_auth.pony # Authentication protocol unit tests (SCRAM, unsupported auth)
363+
_test_md5.pony # MD5 integration tests
360364
_test_query.pony # Query integration tests
361365
_test_response_parser.pony # Parser unit tests + test message builders
362366
_test_frontend_message.pony # Frontend message unit tests

0 commit comments

Comments
 (0)