Skip to content

Reuse user accounts in AJAX test suites.#12599

Closed
peterwilsoncc wants to merge 4 commits into
WordPress:trunkfrom
peterwilsoncc:try/64894-faster-ajax-tests
Closed

Reuse user accounts in AJAX test suites.#12599
peterwilsoncc wants to merge 4 commits into
WordPress:trunkfrom
peterwilsoncc:try/64894-faster-ajax-tests

Conversation

@peterwilsoncc

@peterwilsoncc peterwilsoncc commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Try speeding up the AJAX test suite by re-using roles between tests.

Looks to save about a minute on the full PHPUnit action (which is only about a second on each individual test suite).

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

Use of AI Tools

VS Code/Co-pilot type ahead.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@peterwilsoncc
peterwilsoncc marked this pull request as ready for review July 20, 2026 04:14
@github-actions

github-actions Bot commented Jul 20, 2026

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 peterwilsoncc, mukesh27.

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

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

This PR updates the AJAX PHPUnit base test case to reduce repeated user creation by caching a user ID per role when switching roles via _setRole(), with the intent of speeding up AJAX test execution.

Changes:

  • Add a _user_ids property to store user IDs created for specific roles.
  • Update _setRole() to reuse a previously created user ID for the requested role instead of always creating a new user.

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

Comment thread tests/phpunit/includes/testcase-ajax.php Outdated
Comment thread tests/phpunit/includes/testcase-ajax.php Outdated
@peterwilsoncc
peterwilsoncc dismissed mukeshpanchal27’s stale review July 20, 2026 04:58

Bot was correct, time advantage was chance (probably due to lack of people around).

@peterwilsoncc
peterwilsoncc requested a review from Copilot July 20, 2026 04:59

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

tests/phpunit/includes/testcase-ajax.php:22

  • The docblock is now slightly misleading: it refers to self::_setRole() (suggesting a static call) and it no longer accurately describes how the cache is populated (it’s filled in set_up_before_class()). It also lacks an @var tag, unlike other properties in this class.
	/**
	 * User IDs created by self::_setRole().
	 *
	 * This stores the user IDs of various roles to allow for reuse.
	 */

Comment thread tests/phpunit/includes/testcase-ajax.php Outdated
@peterwilsoncc

Copy link
Copy Markdown
Contributor Author

This is a nope. Creating the shared fixtures in the test suite slows things down rather than speeds thigns up.

A lot of accounts are created but evidently fewer than this PR creates.

@peterwilsoncc
peterwilsoncc deleted the try/64894-faster-ajax-tests branch July 20, 2026 05:40
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.

3 participants