Repository navigation
Fixes 33537: add JDBI test decorators for transaction and SQL-count assertions - #33539
Conversation
…ssertions
Three instruments in it/util, which pom.xml already packages into the test-jar,
so Collate ITs can import them without copies:
SqlQueryCounter counts statements matching a fragment, scoped to the
calling thread or - via forRequests - to statements
issued while serving an HTTP request
SqlFailureProbe throws once from logAfterExecution, so the statement has
really run before the caller sees the error and a
rollback has something to undo
TransactionCounter counts commits and rollbacks on the calling thread
Without these, a write path that produces the right rows through two
autocommits is indistinguishable from one that uses a single transaction: the
final state matches and only a failure between them reveals the difference.
That is how the Collate dashboard-chart delete bug hid, and #33359/#33360/#33361
were all found with these on a branch.
SqlQueryCounter is unchanged from that branch. SqlFailureProbe gains the
forRequests scoping the REST-driven tests need, and TransactionCounter is
promoted out of an IT inner class.
SqlTestDecoratorsIT self-tests all three against the live Jdbi: the counter
counts only matching statements, the probe fires exactly once and only on a
match, the transaction counter separates commits from rollbacks, and each
restores the application's logger/handler on close. A miscounting instrument
would make every assertion built on it quietly wrong.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
| public static SqlFailureProbe forRequests( | ||
| final Jdbi jdbi, final String fragment, final Supplier<RuntimeException> failure) { | ||
| return new SqlFailureProbe( | ||
| jdbi, fragment, failure, () -> RequestLatencyContext.getContext() != null); |
There was a problem hiding this comment.
forRequests accepts every worker with any active RequestLatencyContext, while this probe is installed on the application-wide Jdbi logger. If another HTTP request concurrently executes SQL containing the same fragment, it can consume the failure intended for the test request. The target request then does not fail as expected, making atomicity assertions flaky or misleading. The scope needs to identify the specific request under test rather than any active request.
✅ Playwright Results — workflow succeededValidated commit ✅ 4473 passed · ❌ 0 failed · 🟡 8 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 34m 18s ⏱️ Max setup 4m 29s · max shard execution 21m 52s · max shard-job elapsed before upload 24m 59s · reporting 20s 🌐 219.51 requests/attempt · 2.23 app boots/UI scenario · 40.75% common-shard skew Optimization targets still in progress:
🟡 8 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
Describe your changes:
Fixes #33537 — prerequisite for #33358. Salvaged from the closed PR #33248 (tracking: #33528).
Every atomicity and SQL-count assertion in the #32946 epic needs to observe what the database layer
actually did. Today there is no way to, so a write path that produces the right rows through two
autocommits is indistinguishable from one that uses a single transaction — the final state
matches, and only a failure between them reveals the difference. That is precisely how the Collate
dashboard-chart delete bug hid, and #33359, #33360 and #33361 were all found with these instruments
on a branch.
Three classes in
it/util/, whichpom.xmlalready packages into the test-jar(
<include>org/openmetadata/it/util/**</include>), so Collate ITs can import them with no copies:SqlQueryCounterSqlLoggerand counts statements matching a fragment. Scoped to the calling thread, or viaforRequeststo statements issued while serving an HTTP request (RequestLatencyContext).SqlFailureProbelogAfterExecution, so the statement has really executed before the caller sees the error — a rollback then has something to undo. Same two scopings.TransactionCounterDelegatingTransactionHandlercounting commits and rollbacks on the calling thread.SqlQueryCounteris unchanged from the branch.SqlFailureProbegains theforRequestsscoping theREST-driven tests need (and an
injected()accessor).TransactionCounteris promoted out of an ITinner class into a reusable public class.
Type of change:
High-level design:
Test infrastructure only — no production code is touched. Each decorator installs itself into the
application's live
Jdbiin its constructor and restores the previous logger/handler inclose(),so every use is try-with-resources and any test class using them is
@Isolated.SqlFailureProbethrows fromlogAfterExecutionrather thanlogBeforeExecutiondeliberately: thepoint is to fail after a real write, which is what makes rollback assertions meaningful.
Tests:
Use cases covered
Unit tests
SqlTestDecoratorsITself-tests all three against the liveJdbi— because a miscounting instrumentmakes every assertion built on it quietly wrong:
counterCountsOnlyMatchingStatements— two matching, one not; count is 2.counterRestoresTheSqlLoggerOnClose— the application's logger is the same instance afterwards.probeFailsTheMatchingStatementExactlyOnce— throws once, is then spent, and the retry succeeds.probeIgnoresStatementsThatDoNotMatch— a non-matching statement does not spend the probe.transactionCounterSeparatesCommitsFromRollbacks— 1 commit / 0 rollbacks, then 1 / 1 after afailed unit; handler restored on close.
Backend integration tests
This PR is integration-test infrastructure.
SqlTestDecoratorsITruns in the IT lane against thebootstrapped server on both database profiles.
Ingestion integration tests
Not applicable.
Playwright (UI) tests
Not applicable — no UI change.
Manual testing performed
mvn -pl openmetadata-integration-tests test-compile— BUILD SUCCESS (run after reinstallingopenmetadata-spec/common/sdk/openmetadata-service, since a Lombok cascade otherwise hidesreal errors behind unrelated ones).
mvn spotless:apply -pl openmetadata-integration-tests— clean.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #33537.🤖 Generated with Claude Code
The PR is not yet safe to merge because REST-driven tests cannot use the failure probe to inject failures into server-side SQL execution.
Findings
Summary
This PR adds reusable JDBI test decorators for counting SQL statements and transaction outcomes and for injecting post-execution failures.
Diagram
Reviews (2) · Last reviewed commit: "Add unit coverage for the decorators; ma..."