test: real-database integration coverage for the analytics queue table - #20
Merged
Conversation
There was a problem hiding this comment.
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.phpwith 6 integration tests for install/schema, insert round-trip, batch draining, capacity semantics, and concurrentFOR UPDATEclaims. - 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.
tomasstark
force-pushed
the
test/analytics-queue-integration
branch
from
July 15, 2026 13:08
7130591 to
ac70456
Compare
|
🎉 This PR is included in version 1.3.0-beta.11 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
This PR adds real-database integration coverage for
Analytics_Queue_Table— the SQL semantics the unit suite's in-memorywpdbspy records but cannot execute.Stacked on #17 (base:
feat/analytics-batch-buffer): review only the test diff here; the stack lands onbetaas one work package once #17 merges.Context
#17 gained two SQL-level behaviors late in review — the
FOR UPDATEclaim 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):install()materializes the exact dbDelta schema (DESCRIBE-verified) and records the version option; a version-current re-run provably leaves existing rows untouched.created_atis current UTC.claim_batch()returns oldest-first, deletes what it returns, and reports a drained buffer as an empty claim.is_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 UPDATEclaim — 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 = 1to 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 TABLErewrite is disabled (temporary tables are invisible to the second connection) and cleanup is explicit, sinceclaim_batch()'s ownCOMMITends the per-test rollback wrapper.Verification
composer lint,phpcs(WordPress-VIP-Go),phpstan(level 5) clean.StatusRoutingTest) — the Integration matrix on this PR is the gate.