Skip to content

Fixes 33537: add JDBI test decorators for transaction and SQL-count assertions - #33539

Merged
harshach merged 2 commits into
mainfrom
harshach/it-jdbi-test-decorators
Sep 18, 2026
Merged

harshach merged 2 commits into
mainfrom
harshach/it-jdbi-test-decorators

Conversation

@harshach

@harshach harshach commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

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/, which pom.xml already packages into the test-jar
(<include>org/openmetadata/it/util/**</include>), so Collate ITs can import them with no copies:

Class What it does
SqlQueryCounter Decorates the live SqlLogger and counts statements matching a fragment. Scoped to the calling thread, or via forRequests to statements issued while serving an HTTP request (RequestLatencyContext).
SqlFailureProbe Throws once, from logAfterExecution, so the statement has really executed before the caller sees the error — a rollback then has something to undo. Same two scopings.
TransactionCounter A DelegatingTransactionHandler counting commits and rollbacks on the calling thread.

SqlQueryCounter is unchanged from the branch. SqlFailureProbe gains the forRequests scoping the
REST-driven tests need (and an injected() accessor). TransactionCounter is promoted out of an IT
inner class into a reusable public class.

Type of change:

  • Improvement

High-level design:

Test infrastructure only — no production code is touched. Each decorator installs itself into the
application's live Jdbi in its constructor and restores the previous logger/handler in close(),
so every use is try-with-resources and any test class using them is @Isolated.

SqlFailureProbe throws from logAfterExecution rather than logBeforeExecution deliberately: the
point is to fail after a real write, which is what makes rollback assertions meaningful.

Tests:

Use cases covered

  • A test can assert "this write is one transaction, not three".
  • A test can assert "this read runs N statements" and keep it from regressing.
  • A test can inject a failure or a deadlock after a real statement and assert the rollback.

Unit tests

SqlTestDecoratorsIT self-tests all three against the live Jdbi — because a miscounting instrument
makes 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 a
    failed unit; handler restored on close.

Backend integration tests

This PR is integration-test infrastructure. SqlTestDecoratorsIT runs in the IT lane against the
bootstrapped server on both database profiles.

Ingestion integration tests

Not applicable.

Playwright (UI) tests

Not applicable — no UI change.

Manual testing performed

  1. mvn -pl openmetadata-integration-tests test-compile — BUILD SUCCESS (run after reinstalling
    openmetadata-spec/common/sdk/openmetadata-service, since a Lombok cascade otherwise hides
    real errors behind unrelated ones).
  2. mvn spotless:apply -pl openmetadata-integration-tests — clean.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #33537.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable.
  • For UI changes: not applicable.
  • I have added tests and listed them above.

🤖 Generated with Claude Code

RetriggerConfidence Score: 4/5

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

  1. P1 REST failure injection removed ▶
  2. P1 Request scope is too broad ▶
Summary

This PR adds reusable JDBI test decorators for counting SQL statements and transaction outcomes and for injecting post-execution failures.

  • Adds focused unit and live-database self-tests for matching, restoration, thread scoping, and concurrency.
  • Uses atomic counters and an atomic one-shot claim for thread-safe observations.
  • The latest revision fixes the probe’s exactly-once race but removes the request-scoped failure-injection API needed by REST-driven tests.
Diagram
sequenceDiagram
  participant Test as Integration test thread
  participant Probe as SqlFailureProbe
  participant HTTP as REST server worker
  participant DB as JDBI / Database
  Test->>Probe: Install calling-thread-scoped probe
  Test->>HTTP: Send REST request
  HTTP->>DB: Execute matching SQL
  DB-->>Probe: logAfterExecution on worker thread
  Probe-->>Probe: Scope rejects worker thread
  HTTP-->>Test: Request completes without injected failure
Loading

Reviews (2) · Last reviewed commit: "Add unit coverage for the decorators; ma..."

…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>
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This 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 skip-pr-checks label.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 17, 2026
public static SqlFailureProbe forRequests(
final Jdbi jdbi, final String fragment, final Supplier<RuntimeException> failure) {
return new SqlFailureProbe(
jdbi, fragment, failure, () -> RequestLatencyContext.getContext() != null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Request scope is too broad

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.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit f54ccfe32a05b6a3ff700391d127ec8e9a574d00 in Playwright run 35251790917, attempt 1.

✅ 4473 passed · ❌ 0 failed · 🟡 8 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking 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:

  • Common shard skew was 40.75% (convergence target: at most 15%).
  • Browser traffic was 219.51 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10638 boots / 4770 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 130 0 0 0 0 0
🟡 Shard chromium-01 164 0 1 0 0 0
✅ Shard chromium-02 172 0 0 0 0 0
✅ Shard chromium-03 177 0 0 0 0 0
✅ Shard chromium-04 227 0 0 0 0 0
✅ Shard chromium-05 151 0 0 0 0 0
✅ Shard chromium-06 190 0 0 0 0 0
✅ Shard chromium-07 159 0 0 0 0 0
✅ Shard chromium-08 180 0 0 0 0 0
✅ Shard chromium-09 172 0 0 0 0 0
🟡 Shard chromium-10 165 0 1 0 0 0
✅ Shard chromium-11 175 0 0 0 0 0
🟡 Shard chromium-12 164 0 1 0 0 0
✅ Shard chromium-13 201 0 0 0 0 0
✅ Shard chromium-14 179 0 0 0 0 0
🟡 Shard chromium-15 181 0 1 0 0 0
✅ Shard chromium-16 218 0 0 1 0 0
🟡 Shard chromium-17 210 0 1 0 0 0
✅ Shard chromium-18 153 0 0 0 0 0
🟡 Shard chromium-19 198 0 1 0 0 0
✅ Shard chromium-20 147 0 0 0 0 0
✅ Shard chromium-21 167 0 0 0 0 0
🟡 Shard chromium-22 161 0 2 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 80 0 0 0 0 0
✅ Shard import-export-02 70 0 0 0 0 0
✅ Shard ingestion-01 43 0 0 0 0 0
✅ Shard ingestion-02 55 0 0 0 0 0
✅ Shard reindex-01 28 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 8 flaky test(s) (passed on retry)
  • Pages/ServiceEntity.spec.ts › Delete Database Service (shard chromium-01, 1 retry)
  • Pages/UserDetails.spec.ts › Create team with domain and verify visibility of inherited domain in user profile after team removal (shard chromium-10, 1 retry)
  • Pages/Users.spec.ts › Admin soft & hard delete and restore user from profile page (shard chromium-12, 1 retry)
  • Pages/Entity.spec.ts › Announcement create, edit & delete (shard chromium-15, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-17, 1 retry)
  • Features/ContextCenterArchive.spec.ts › file in deleted folder is absent from search and not added to archive (shard chromium-19, 1 retry)
  • Features/Announcements/AnnouncementEntity.spec.ts › creates an announcement on a domain (shard chromium-22, 1 retry)
  • Pages/Domains.spec.ts › shows preview modal on cross-domain move and commits on Move Anyway (shard chromium-22, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@harshach
harshach added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit e05e37f Sep 18, 2026
149 of 152 checks passed

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to assert transaction boundaries or SQL counts in integration tests

2 participants