Skip to content

Tests: Cover transient timeout handling with and without an external object cache - #1

Open
AceMedia wants to merge 1 commit into
dhrupo:52345-transient-timeout-failurefrom
AceMedia:ticket/52345-transient-tests
Open

AceMedia wants to merge 1 commit into
dhrupo:52345-transient-timeout-failurefrom
AceMedia:ticket/52345-transient-tests

Conversation

@AceMedia

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/52345

This adds regression tests on top of dhrupo's work in WordPress#14340. It is built on their exact head (5a233df) and changes no production code. I am offering it as a tests-only commit for you to take or leave.

Two other open PRs touch the same transient functions and the same test files, so I have kept clear of them: WordPress#13101 (#65863, orphaned timeout rows on delete) and WordPress#12523 (#33561, return false when the timeout row is missing). I did not build on either. They edit different parts of option.php, but all three append tests to the end of the same test files, so those hunks will need a rebase whichever lands first.

What the tests cover

On the database path (no external object cache):

  • an expiring transient and site transient write a timeout row and a value row, neither autoloaded
  • a transient without an expiry writes only a value row (autoloaded for transients)
  • adding an expiry to an existing transient that has none succeeds and leaves the value non-autoloaded
  • if the value row cannot be inserted, set_transient() and set_site_transient() return false and the set action does not fire
  • an unrelated earlier database error left in $wpdb->last_error does not stop a transient being set over an orphaned timeout row. This guards the get_option() fallback in the PR; removing only that clause makes this test fail while the PR's own orphan test still passes.

With an external object cache (simulated):

  • set, get, delete and set-again for transients and site transients, with and without an expiry, use only the object cache group
  • no option or sitemeta rows are written and no query mentions the transient, even with the timeout INSERT rigged to fail

These run on single site and multisite.

Results

Run through my local setup on PHP 8.4.25, PHPUnit 9.6.35 and MariaDB 10.11.18: Tests_Option_Transient 21 tests, 89 assertions, and Tests_Option_SiteTransient 13 tests, 46 assertions, each with one skip, on both single site and multisite. PHPCS is clean on the two files.

With the PR's src change reverted to its base, only the three failure-path tests the PR already contains fail. All of my added tests pass there as well. They are guards on the changed code paths and on the external cache behaviour rather than tests of a new defect, and I would rather say so than imply otherwise.

Limits

  • Only the files tests/phpunit/tests/option/transient.php and siteTransient.php were run, not the wider option or full suite.
  • Tested on MariaDB 10.11 only, not MySQL or other PHP versions.
  • The external cache is the default in-memory cache flagged as external with wp_using_ext_object_cache( true ). It is not a real Redis or Memcached drop-in, and it ignores TTLs.
  • I tried WordPress Playground to reproduce the original problem on stock WordPress, but no Playground browser session was connected, so I have no Playground observations to report.
  • I noticed that set_site_transient() has no equivalent of the "existing value without a timeout" branch the PR changes in set_transient(), so a failed timeout write there is not handled. I have not tested it as a bug and have left it for the author to judge.

AI assistance: Codex and Claude helped me assess the issue, write the tests and run the checks. I have reviewed the code myself. The test results are from automated runs through my local test setup.

…object cache.

Adds regression coverage alongside the change for transients stored without their timeout row. The new tests check the row layout and autoload state on the database path, the value-insert failure path, and that an unrelated earlier database error does not block setting a transient over an orphaned timeout row. They also check that, with an external object cache, transients and site transients use only the object cache and never write or query option rows. The external cache is simulated by flagging the default in-memory cache as external.

See https://core.trac.wordpress.org/ticket/52345

Props dhrupo.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shanerounce.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant