Skip to content

Fix test coverage gaps for pg_stat_statements on PG 17+ (issue #127)#134

Merged
lesovsky merged 2 commits into
masterfrom
develop
May 18, 2026
Merged

Fix test coverage gaps for pg_stat_statements on PG 17+ (issue #127)#134
lesovsky merged 2 commits into
masterfrom
develop

Conversation

@lesovsky
Copy link
Copy Markdown
Owner

Summary

  • Fixes two structural problems in statements_test.go that caused PG 17/18 to be silently untested
  • No production code changes needed — the query routing for PG 17+ was already correct

Root cause

Bug 1 — t.Skipf inside a bare for loop.
The pg_stat_statements_timing and Test_StatStatementsReportQueries loops called t.Skipf when a PG instance wasn't available. t.Skipf marks the current test as skipped and stops execution — so the very first missing version (9.5) caused the entire suite to skip, and PG 17/18 timing/report queries never ran against a real database.

Bug 2 — Missing PG 17/18 cases in routing unit tests.
TestSelectStatStatementsTimingQuery and TestSelectQueryReportQuery only asserted routing up to PG 13 (130000). A regression in the PG 17+ branch would go completely undetected by these tests.

Fixes

  • Converted timing and WAL loops to per-version t.Run sub-tests — missing instances now skip only that version
  • Extended WAL stats test to cover PG 13–18 (was hardcoded to PG 13 only)
  • Added PG 14/16/17/18 assertions to both routing unit tests, confirming that PG 17+ selects the blk_read_time-free query variants

Test plan

  • TestSelectStatStatementsTimingQuery — PG 17/18 assert PgStatStatementsTimingPG17
  • TestSelectQueryReportQuery — PG 17/18 assert PgStatStatementsReportQueryPG17
  • pg_stat_statements_timing/170000 and /180000 — now run and pass against real PG
  • Test_StatStatementsReportQueries/version/170000 and /180000 — same
  • Full go test ./... passes

Closes #127

🤖 Generated with Claude Code

Alexey Lesovsky and others added 2 commits May 18, 2026 18:18
Two structural problems in statements tests:

1. t.Skipf inside a bare for-loop caused the entire timing/report/wal
   suite to be skipped when the first PG version (9.5) was unavailable.
   Timing and report query integration tests never ran against PG 17/18.

2. TestSelectStatStatementsTimingQuery and TestSelectQueryReportQuery
   only asserted version routing up to PG 13, so a regression in the
   PG 17+ routing would go undetected.

Fixes:
- Split timing and WAL loops into per-version t.Run sub-tests; missing
  instances now skip only that version, not the entire suite.
- Extend WAL stats test to cover PG 13-18 (was hardcoded to PG 13).
- Add PG 14/16/17/18 cases to both unit routing tests, asserting that
  PG 17+ returns the blk_read_time-free PG17 query variants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…version

Convention: PGxx suffix marks a query valid from PG xx (now superseded);
Default marks the query for the current/latest supported version.

Previously violated by two files:
- wal.go: PgStatWALDefault covered PG 14-17 (not latest);
  PgStatWALPG18 covered PG 18+ (latest).
- statements.go: PgStatStatementsTimingDefault / ReportQueryDefault
  covered PG 13-16; PG17 variants covered PG 17+ (latest).

Renames:
- PgStatWALDefault       → PgStatWALPG14
- PgStatWALPG18          → PgStatWALDefault
- PgStatStatementsTimingDefault      → PgStatStatementsTimingPG13
- PgStatStatementsTimingPG17         → PgStatStatementsTimingDefault
- PgStatStatementsReportQueryDefault → PgStatStatementsReportQueryPG13
- PgStatStatementsReportQueryPG17    → PgStatStatementsReportQueryDefault

Updated: selector functions, view.go initial templates, all test references.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lesovsky lesovsky merged commit 3dfcc54 into master May 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pg_stat_statements blk_read_time missing since PG 17

1 participant