neon-cold-start-probe/test-fixtures/local-postgres-verification.md
caelum0x 5c1758578f fix: clean output for sslmode=require, real arg validation, --version, closing CTA line
- normalize sslmode=require/prefer/verify-ca to verify-full so pg's 8-line
  SECURITY WARNING no longer precedes every Neon probe
- --repeat/--timeout/--every-seconds/--cold-threshold-ms are validated; a bad
  or missing value used to exit 1 silently
- reject non-postgres:// arguments and unknown flags with a clear message
- pay one-time DNS/TLS process costs before probe 1
- output ends with one plain line pointing at the Neon cold-start page
- README: 10-second quickstart, real output sample, copy matches the page

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-17 20:01:34 +03:00

4.7 KiB

Verification run (real, not mocked)

Date: 2026-11-17. Environment: this build/test had no Neon account credentials available (no NEON_* in ~/products/.env; the Neon MCP server requires an interactive OAuth sign-in this environment can't complete). Everything below ran against a real local Postgres 16 container instead, to prove the connect/query/timing/retry/classification code is correct — it does not reproduce a real Neon suspend/resume cycle (a local container never suspends).

docker run -d --name ncsp-test-pg -e POSTGRES_PASSWORD=test -p 15499:5432 postgres:16

Single probe:

$ node bin/neon-cold-start-probe.mjs "postgres://postgres:test@127.0.0.1:15499/postgres"
probe 1/1: connect=73ms query=3ms total=77ms [warm]

4 probes, 2s apart:

$ node bin/neon-cold-start-probe.mjs --url "postgres://postgres:test@127.0.0.1:15499/postgres" --repeat 4 --every-seconds 2
probe 1/4: connect=42ms query=4ms total=46ms [warm]
probe 2/4: connect=18ms query=3ms total=21ms [warm]
probe 3/4: connect=16ms query=2ms total=18ms [warm]
probe 4/4: connect=793ms query=27ms total=819ms [COLD]

summary: min=18ms p50=21ms p95=819ms max=819ms (1/4 probes >= 500ms, 0 failed)

That one 819ms reading against a local container that never suspends is real and reproducible on this machine (Docker Desktop on macOS proxies container ports through a VM; under any concurrent load — this run had a fresh postgres:16 image pulling moments earlier — a single connection can spike well past the 500ms default threshold with nothing to do with a cold start). This is the actual reason the README tells people to take more than one sample before concluding a connection felt slow because of a suspended compute specifically. The --json run below shows the same thing at a larger scale (a 1664ms and a 434ms reading, both against the same idle local container, both false "cold" by the classifier):

$ node bin/neon-cold-start-probe.mjs "postgres://postgres:test@127.0.0.1:15499/postgres" --repeat 2 --json
{
  "results": [
    { "ok": true, "error": null, "connectMs": 1474.68875, "queryMs": 190.176875, "totalMs": 1664.865625 },
    { "ok": true, "error": null, "connectMs": 406.783542, "queryMs": 27.964, "totalMs": 434.747542 }
  ],
  "summary": { "probes": 2, "failed": 0, "minMs": 434.747542, "p50Ms": 434.747542, "p95Ms": 1664.865625, "maxMs": 1664.865625, "coldThresholdMs": 500, "coldCount": 1 }
}

Failure paths, also real:

$ node bin/neon-cold-start-probe.mjs "postgres://postgres:test@127.0.0.1:19999/postgres" --timeout 2
probe 1/1: FAILED (connect ECONNREFUSED 127.0.0.1:19999)
# exit code 1

$ node bin/neon-cold-start-probe.mjs "postgres://postgres:wrongpass@127.0.0.1:15499/postgres"
probe 1/1: FAILED (password authentication failed for user "postgres")
# exit code 1

$ node bin/neon-cold-start-probe.mjs
error: a connection string is required (positional arg, --url, or DATABASE_URL). Run with --help.
# exit code 1

$ DATABASE_URL="postgres://postgres:test@127.0.0.1:15499/postgres" node bin/neon-cold-start-probe.mjs
probe 1/1: connect=122ms query=24ms total=146ms [warm]
# exit code 0

Not verified live: a real Neon (or other serverless-Postgres) project actually suspending and this tool catching the real wake-up latency on the next probe. Logged honestly rather than faked — see the README's "Honest limits" section.

2026-11-17 (v0.1.1) re-verification

Throwaway Postgres 16.16 (initdb in /tmp, port 55439, self-signed TLS cert). Machine load average was above 70 during these runs, so the absolute numbers are noisy.

Bugs found by running it the way the README says, all fixed in v0.1.1:

  • ?sslmode=require (what every Neon connection string ships with) printed an 8-line pg SECURITY WARNING before the first probe. Now normalized to verify-full, which is what pg already did for require, silently.
  • --repeat abc and a bare --repeat exited 1 with no message at all.
  • A non-URL argument ("not a url") failed as getaddrinfo ENOTFOUND base.
  • --version answered "a connection string is required".
  • Unknown flags were silently ignored.

TLS path, CA trusted via NODE_EXTRA_CA_CERTS:

$ neon-cold-start-probe "postgres://postgres@localhost:55439/postgres?sslmode=require" --repeat 5 --every-seconds 1
probe 1/5: connect=202ms query=10ms total=212ms [warm]
probe 2/5: connect=55ms query=10ms total=64ms [warm]
probe 3/5: connect=39ms query=1ms total=41ms [warm]
probe 4/5: connect=299ms query=15ms total=314ms [warm]
probe 5/5: connect=36ms query=3ms total=39ms [warm]

summary: min=39ms p50=64ms p95=314ms max=314ms (0/5 probes >= 500ms, 0 failed)

Same server, CA not trusted: probe 1/1: FAILED (self-signed certificate; ...), exit 1, no warning noise. psql confirmed the session was really TLS (pg_stat_ssl.ssl = t).