Expand description
A throwaway Postgres for the lifetime of one command.
Replaces the sqlx-cli shell-out: the database is created and migrated
in-process through sqlx, using the same migrations/ directory the
server embeds via server::db::MIGRATOR. One set of migrations, one
migrator, no second implementation that can drift.
initdb and pg_ctl remain external programs because they are external
programs; there is no library form of them.
The cluster inherits the scheduling priority of xtask postgres itself, and
a non-root process cannot lower its nice value again. Callers must not nice
xtask postgres, only the command it runs.
ModulesΒ§
- sweep π
- Removal of throwaway clusters a killed
xtask postgresleft in RAM.
StructsΒ§
- Postgres
- A running cluster that stops itself when dropped.
ConstantsΒ§
- CLUSTER_
PREFIX π - CONNECTIONS π
- A full workspace test run at default parallelism holds well over the stock 100 connections.
- DURABILITY_
OFF π - Durability is off on purpose. This cluster is initdbβd moments earlier and dies with the container, so there is nothing for it to protect β every fsync is pure cost, paid on cloud block storage, and 275 of the tests create and migrate a database of their own. Measured worth ~2m30s of a test run.
- PORT_
RANGE π - Ports tried in order. No allocator to lean on: a port that cannot be bound is
skipped without starting a server, and
pg_ctl -wexiting non-zero covers a port taken between the probe and the start. - RAM_
DISK π - Where the cluster lives when there is room: in RAM. Every test database is
created and dropped, and each
DROP DATABASEwaits for an immediate checkpoint; on a disk shared with other runs one such checkpoint was seen to spend 17 s inwrite()while every new connection queued behind it. - RAM_
DISK_ πMIN_ FREE - A full workspace run peaks well under this.
- SETUP_
DURATIONS_ πSINCE - First server major version whose
log_connectionsacceptssetup_durations; earlier ones take only a boolean and refuse to start on the string. - SOCKET_
PATH_ πMAX - Longest unix socket path the kernel accepts,
sun_pathless its NUL. - TIMEOUTS π
- Bounds on how long the server will let a client misbehave.
StaticsΒ§
- MIGRATOR π
- The projectβs migrations, embedded at compile time from the same directory
server::db::MIGRATORreads. Embedding needs no database, which is what lets this binary be built before the server it goes on to test.
FunctionsΒ§
- check_
socket_ πpath - cluster_
root π - create_
and_ πmigrate - first_
started π - Tries each probed-free port in order. A port refused by
probecosts no server start; one thatattemptfails on (taken since the probe, or a server that cannot start at all) moves on to the next. - log_
tail π - parse_
major π - port_
is_ πfree - ram_
disk_ πhas_ room - run π
- Children run in their own group so a terminal Ctrl-C cannot kill them half-way and be mistaken for a failure; xtaskβs own termination handling decides instead.
- server_
major π - server_
options π - The socket directory lives inside PGDATA: a shared /tmp is not writable the same way in every container, and its lock file is where that first shows up.
- start
- initdb, start, create the database, migrate it.
- start_
on_ πfree_ port