tests: add integration tests, perf tests dircet vs gerpo and perf test print results to mr - #51
Merged
Conversation
…r matrix Introduces tests/integration/ — a new suite that runs against a real PostgreSQL brought up via docker-compose. Every test is parameterised over pgx5/pgx4/database-sql through the forEachAdapter helper, so bodies speak only to Repository[T] and know nothing about the underlying driver. - docker-compose.yml spins up postgres:16 on :5433 (keeps 5432 free for the existing benchmark). - schema.sql defines users/posts/comments covering uuid, nullable text, int, bool, nullable timestamptz, FK cascade and soft delete. - setup_test.go/adapters_test.go/repos_test.go/seed_test.go form the scaffolding; TestMain skips cleanly if GERPO_INTEGRATION_DB_URL is unset so `go test ./...` stays green without Docker. - Build tag //go:build integration keeps the suite out of the default run. - .gitlab-ci.yml adds an integration job with a postgres:16 service. Also fixes a latent bug in sqlstmt/sqlpart/group.go: GroupBy was concatenating column expressions without a ", " separator, producing malformed SQL the moment more than one column was grouped. The mock tests never exercised this path; the integration smoke test caught it on the first run.
…rt/Update/Delete 12 tests, each parameterised across pgx5/pgx4/database-sql via forEachAdapter. Exercises happy paths plus ErrNotFound semantics for GetFirst, Update and Delete. Insert_WithExclude confirms that excluded fields fall back to the column's DEFAULT on the database side. Posts repo is used here because it has no persistent query or soft delete — keeps the CRUD contract clean; users repo will be exercised separately in the soft-delete suite.
Adds where_test.go, order_pagination_test.go, exclude_only_test.go and
persistent_query_test.go — 29 test functions, each running on all three
adapters. Covers every public query operator (EQ/NEQ/LT/LTE/GT/GTE/IN/NIN,
6 LIKE ops and their _ic variants, EQ(nil)/NEQ(nil), AND/OR/Group),
ORDER BY + multi-field sort, pagination edge cases, Exclude/Only on
SELECT and UPDATE, persistent LeftJoin/InnerJoin with a virtual column
(post_count), persistent Where hiding soft-deleted rows, and persistent
+ per-request Where composition.
The suite uncovered three real bugs, fixed in the same commit:
1. sqlstmt/first.go, sqlstmt/list.go emitted "ORDER BY ... GROUP BY ..."
which is invalid SQL. Swapped so GROUP BY precedes ORDER BY.
2. sqlstmt/sqlpart/where.go generated "col LIKE CONCAT('%', ?, '%')".
PostgreSQL cannot infer the parameter type inside CONCAT when another
parameter of a different type is present, or when the whole thing is
wrapped in LOWER() for case-insensitive variants. All LIKE operators
now wrap the placeholder in CAST(? AS text), which is both
PostgreSQL- and MySQL-compatible. Unit tests in
sqlstmt/sqlpart/where_test.go updated to the new SQL.
3. query/linq/pagination.go computed offset as (page-1)*size in uint64,
which underflowed to ~1.8e19 when Size() was set without Page(),
producing "bigint out of range". Added an early return when page
is zero.
… error transformer; fix pgx tx state bug
Closes the advanced-feature gap in tests/integration/. 26 functions,
3 adapters each, 78 subtests in total.
- hooks_test.go: before/after insert/update, afterSelect for GetFirst
and GetList, hook stacking, mutation from BeforeInsert persisting.
- soft_delete_test.go: Delete rewrites to UPDATE deleted_at, soft-deleted
rows hidden from the repo, repeated Delete returns ErrNotFound, row
can be restored via direct SQL.
- virtual_test.go: virtual columns are ignored on INSERT and UPDATE,
and reflect the real underlying state.
- transactions_test.go: Commit, Rollback, isolation from outside
connections until commit, RollbackUnlessCommitted as both a no-op
(after Commit) and a real rollback (without it).
- cache_test.go: CtxCache returns the cached value even after an
external DB change; Insert through the repo invalidates the cache;
missing middleware degrades gracefully; different contexts keep
independent caches.
- error_transformer_test.go: ErrNotFound swapped for a domain error
across GetFirst/Update/Delete; happy path unaffected; non-NotFound
errors (FK violation) stay untouched.
Also fixes pgx5/tx.go and pgx4/tx.go: txWrap used value receivers, so
Commit()'s state changes never stuck to the original instance, and
RollbackUnlessCommitted() tried to roll back an already-committed tx
("tx is closed"). Methods moved to pointer receivers; Commit() now
sets commited=true and Rollback() clears rollbackUnlessCommittedNeeded,
mirroring databasesql/tx.go which was already correct.
…able
Runs every Direct/Gerpo bench pair via testing.Benchmark() and emits a
padded table to t.Log so the overhead picture lands in one place:
go test -run=TestCompareDirectVsGerpo -v ./tests/
The report header explains that these ratios are pure-overhead numbers
(mock adapter, zero IO) and should not be read as "gerpo uses 3× CPU in
production" — with a real PostgreSQL the per-op gerpo cost (~1 µs)
gets absorbed by network latency.
Adds a bench-diff GitLab CI job that runs on every merge_request_event: it benches the MR head (~10 runs of the mock-db Direct/Gerpo suite), checks out the target branch, benches it the same way, then pipes the two results through benchstat and posts the summary as a comment on the MR via the Notes API. - scripts/bench-diff.sh owns the logic; it's resilient: if BENCH_BOT_TOKEN is missing the comment is skipped but the report still lands in the job log and artifacts (base.txt/head.txt, kept 1 week); if the base revision fails to build the benches, head-only results are reported. - The job is allow_failure: true so a perf regression can't block a merge on its own. - TestCompareDirectVsGerpo now gates on GERPO_BENCH_REPORT=1 so the default `go test ./...` stays under a second instead of spending ~20s on the report. - CLAUDE.md documents the required BENCH_BOT_TOKEN project variable (Developer+, api scope).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #51 +/- ##
==========================================
+ Coverage 61.09% 61.17% +0.07%
==========================================
Files 54 54
Lines 1951 1955 +4
==========================================
+ Hits 1192 1196 +4
Misses 710 710
Partials 49 49 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add .github/workflows/integration.yml running the //go:build integration suite against a postgres:16 service on push and pull_request. - Add .github/workflows/bench-diff.yml posting a benchstat-based summary as a PR comment on every pull_request. Uses the ambient GITHUB_TOKEN with permissions: pull-requests: write — no project secret required. - Rewrite scripts/bench-diff.sh to read GITHUB_BASE_REF / pull request number from GITHUB_EVENT_PATH and POST to the GitHub Notes API. Fails safe: if the base revision cannot run the benches the comment falls back to head-only; if GITHUB_TOKEN is missing the report stays in job logs and the base.txt / head.txt artifacts. - Drop .gitlab-ci.yml — the repository lives on GitHub.
Benchmark diff:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
intgration tests was added
fix some issues
add print rerf tests result to first commit message