Skip to content

Testing Strategy

Mohammad Rasoul Kazemi edited this page Nov 26, 2026 · 2 revisions

Testing Strategy

How KingresDB is tested, layer by layer, and how the layers fit with the independent reviews. The commands for running them are on Development and Testing and Building from Source; this page explains the strategy. The authority is testing.md. No check runs on GitHub: Actions is off for the repository by decision of the project owner, so every suite runs on a developer's machine and its result is recorded in the work log.

Principles

  1. Every phase deliverable includes tests; a phase is not finished while its features have none.
  2. A bug fix starts with a test that fails without the fix.
  3. Tests do not depend on the developer's machine: no fixed ports, no fixed paths outside the test's temporary directory, no network except to servers the test starts.
  4. A flaky test is a bug: fix it or remove it. A TAP file that fails is rerun alone before it is called a real failure (the timing-dependent tests of kingres_shard can fail on a loaded machine); a failure that repeats is a defect.
  5. A fix is trusted only after a later independent review confirms it (Review Process).

Layers

Layer What it proves Tool Where
Unit and regress SQL interface, catalog behaviour, error codes and messages, GUCs, upgrade scripts, hook chaining pg_regress contrib/kingres_*/sql/ and expected/
TAP, one server Crash recovery, restart, background workers, preload, WAL-level behaviour, standbys PostgreSQL TAP tests (Perl) contrib/kingres_*/t/
TAP, several clusters Routing across groups, two-phase commit and its recovery, bucket moves, standbys and promotion, stale-map retry TAP tests that start several clusters contrib/kingres_shard/t/
Ledger Hash chain and Merkle roots against fixed vectors that include DateStyle, extra_float_digits, bytea_output and locale variations (which must not change a hash); tamper detection; independence of the verifier pg_regress and TAP; Go tests contrib/kingres_ledger/, kingres/verifier/
Control plane, unit Pure logic: state machines, task engine, planners, configuration parsing go test (table-driven, -race) *_test.go next to the code
Control plane, integration The agent and manager against real PostgreSQL instances, task resume after a restart, leader election, three-kingresd cluster tests, failover and rebalance go test against instances; KINGRES_PG_BIN set kingres/control-plane/
API contract The spec is valid; every route in the spec exists and every handler is in the spec; responses validate against the schemas npm run check in kingres/api; contract tests on both sides; go generate ./internal/contract regenerates the operation table (a test fails while it is stale) kingres/api, kingres/control-plane, kingres/web
Web Components, accessibility queries, behaviour on API errors; layout, keyboard, axe and the content security policy in a real browser; the real flow end to end Vitest; npm run test:browser; npm run e2e kingres/web/tests, browser-tests, scripts/e2e
Packaging The Debian package installs and the unit starts (test-deb.sh); the image runs a full cluster flow (test-image.sh); the three-node compose cluster forms (test-compose.sh); the release script's gates, checksums and tags (test-release.sh) Container-based scripts, once per major kingres/packaging/test/

Further points:

  • Hook chaining. Every extension has a test that loads another module using the same hook.
  • Documented anomaly. With two-phase commit and no global snapshot (ADR 0009) a cross-shard read can see a partially committed distributed transaction. A test documents it so a later change is noticed.
  • Upgrade. Each extension has a test that upgrades from the oldest supported version and compares the result with a fresh install.
  • Failure tests. Behaviours the architecture document marks as needing verification (simultaneous failure of the map group and a shard group, router behaviour during a switchover, in-doubt transactions after failover) get a test when their feature is built.
  • Assertions. C tests run on a build with assertions enabled (build.sh configures one); the release build recipe turns assertions off, so release artifacts are tested separately by the package tests.

Both PostgreSQL majors

An extension change is complete only when kingres/dev/ext-majors.sh <extension> passes on 18 and 19 with warnings as errors. A second major is a second installation, and each job needs an installation of its own because ext.sh installs into the one it is given. The control plane's integration suite (scripts/run-integration.ps1 -Install <installation>) and the console's end-to-end run (E2E_PG_INSTALL) can be pointed at an installation of another major, so the same suite proves each major. The packaging tests run once per major. The final run of every check on both majors is recorded in the check record that the release script reads (Release Process).

Integration tests and the shared machine

The integration suite of the control plane builds the test binaries for Linux, copies them into WSL2 and runs them against a private PostgreSQL installation, using a port range of its own and throwaway directories. Because two runs of the same lane would share the staging directory, run-integration.ps1 takes a system-wide Windows mutex per lane (Global\kingres-cp-integration followed by the lane's suffix); runs of the same lane on one machine queue behind it, and runs of different lanes (-Lane) run side by side, each with its own staging area, directory of binaries in WSL and, when its extensions differ, its own installation (-Install). The run roots and port slices of run-wsl-tests.sh keep concurrent runs apart. Tests allowed to skip in the WSL run are listed with a reason in scripts/wsl-allowed-skips.txt (the third-party test vectors of the anchoring packages are not in the repository). KINGRES_TEST_KEEP=1 keeps a run's directories for a post-mortem. Each run works in a private copy of an installation; extensions are never installed into a shared one.

Fuzzing and generated comparison

  • Verifier. kingres/verifier/scripts/fuzz.sh [seconds] runs every fuzz target for a short bounded time (the parsers and verifiers of digests, blocks, proofs, signed notes, checkpoints, tile logs, trust files, row files, JSON and the command-line forms). The seed corpora, which are the published vectors, also run in plain go test ./.... One target alone: go test ./internal/proof -run '^$' -fuzz '^FuzzVerify$' -fuzztime 30s. The fixtures come from scripts/gen-fixtures.sh. The script uses few workers and a bounded time per target, because the machine is shared with long jobs. scripts/repro-check.sh builds the release files twice and requires them to be byte for byte the same.
  • Sharding. The reviews of the pushdown work compare generated statements with a single node on both majors and found a critical defect that way (a HAVING without an aggregate).

Mutants

A mutant is a one-line change that removes a fix or flips a condition. The author or reviewer builds it, runs the tests that should catch it and requires failure. Review reports list their mutants with results ("killed" by a named test, or "survived"); a surviving mutant that is not equivalent is a finding about a missing test. Mutants run in private copies of the installation and are never committed.

Independent reviews

Reviews are part of the test strategy: a reviewer who did not write the code reads it against its design, runs the suites on both majors, injects faults, attacks each fix with a script, and runs mutants. See Review Process.

Definition of done

A change is done when it has tests at the right layer and the relevant suites pass locally (C tests on a build with assertions); the formatters and linters pass (Coding Standards); the documentation is updated; any change to an upstream file has a row in the core-patch register (Branching and Synchronisation); a dated work-log entry records what was done, how it was verified and what is still open; and any [Needs verification] item it depends on was checked. A phase is done when every item of its deliverable is done in this sense and its failure tests have been run.

Sources

Clone this wiki locally