Skip to content

test: real-database integration coverage for the analytics queue table - #20

Merged
tomasstark merged 3 commits into
betafrom
test/analytics-queue-integration
Jul 16, 2026
Merged

test: real-database integration coverage for the analytics queue table#20
tomasstark merged 3 commits into
betafrom
test/analytics-queue-integration

Conversation

@tomasstark

Copy link
Copy Markdown
Contributor

This PR adds real-database integration coverage for Analytics_Queue_Table — the SQL semantics the unit suite's in-memory wpdb spy records but cannot execute.

Stacked on #17 (base: feat/analytics-batch-buffer): review only the test diff here; the stack lands on beta as one work package once #17 merges.

Context

#17 gained two SQL-level behaviors late in review — the FOR UPDATE claim transaction and the O(1) id-span capacity probe — that nothing executes against a real database. The existing integration suite (WP tests lib + MySQL 8.0 in CI, WP 6.4/7.0 × PHP 8.1/8.4) is the right home for that proof.

Key Changes

tests/integration/AnalyticsQueueTableTest.php (new, 6 tests):

  • Schemainstall() materializes the exact dbDelta schema (DESCRIBE-verified) and records the version option; a version-current re-run provably leaves existing rows untouched.
  • Round-trip — payloads survive byte-for-byte (multibyte UTF-8 included); created_at is current UTC.
  • Drainclaim_batch() returns oldest-first, deletes what it returns, and reports a drained buffer as an empty claim.
  • Capacity probeis_full() boundary at the cap, plus the documented id-span early-trip: a carved id gap trips the cap with only 2 rows present (the fail-open direction, pinned as intended).
  • FOR UPDATE claim — a second mysqli session holds locks on the oldest rows while the main connection claims: the contending claim must return nothing (never the locked rows, innodb_lock_wait_timeout = 1 to fail fast); after the holder deletes-and-commits, a follow-up claim returns exactly the survivors. Asserts claims are disjoint and exhaustive — no double delivery, no loss.

Test-framework notes (documented in the file header): the suite's CREATE TEMPORARY TABLE rewrite is disabled (temporary tables are invisible to the second connection) and cleanup is explicit, since claim_batch()'s own COMMIT ends the per-test rollback wrapper.

Verification

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new integration test suite that exercises Analytics_Queue_Table against a real MySQL database (instead of the unit suite’s in-memory wpdb spy), to validate SQL-level semantics like dbDelta schema, drain ordering, id-span capacity checks, and SELECT ... FOR UPDATE locking behavior.

Changes:

  • Introduces tests/integration/AnalyticsQueueTableTest.php with 6 integration tests for install/schema, insert round-trip, batch draining, capacity semantics, and concurrent FOR UPDATE claims.
  • Adds explicit setup/teardown handling for real (non-temporary) tables and cleanup in the presence of mid-test COMMITs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/integration/AnalyticsQueueTableTest.php
Comment thread tests/integration/AnalyticsQueueTableTest.php
Comment thread tests/integration/AnalyticsQueueTableTest.php
Comment thread tests/integration/AnalyticsQueueTableTest.php
Base automatically changed from feat/analytics-batch-buffer to beta July 15, 2026 10:02
@tomasstark
tomasstark force-pushed the test/analytics-queue-integration branch from 7130591 to ac70456 Compare July 15, 2026 13:08
@tomasstark
tomasstark merged commit 64f1a84 into beta Jul 16, 2026
5 checks passed
@tomasstark
tomasstark deleted the test/analytics-queue-integration branch July 16, 2026 03:51
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.3.0-beta.11 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants