Skip to content

Tests: Optimize REST server setup in Tests_REST_API - #13694

Open
SainathPoojary wants to merge 3 commits into
WordPress:trunkfrom
SainathPoojary:fix/66074-rest-api-setup
Open

SainathPoojary wants to merge 3 commits into
WordPress:trunkfrom
SainathPoojary:fix/66074-rest-api-setup

Conversation

@SainathPoojary

Copy link
Copy Markdown

Reduces unnecessary REST server setup in Tests_REST_API.

Previously, every test created a Spy_REST_Server and initialized all REST routes, including helper tests that did not need them.

This change initializes the server only where needed using rest_get_server(). The test bootstrap continues to select Spy_REST_Server. Setup and teardown clear the server to preserve test isolation.

Performance

Measured locally across three runs:

Run Trunk Test Time Trunk Wall Time Fix Test Time Fix Wall Time
Run 1 1.593s 1.884s 0.558s 0.852s
Run 2 1.756s 2.049s 0.535s 0.823s
Run 3 1.578s 1.877s 0.551s 0.850s
Average 1.642s 1.937s 0.548s 0.842s

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

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks, and assistance with the PR description. Implementation and testing were made and reviewed by me.


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

github-actions Bot commented Sep 24, 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 sainathpoojary, mindctrl.

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

Comment thread tests/phpunit/tests/rest-api.php Outdated
Comment on lines 1097 to 1100
rest_get_server();

$rest_server = $GLOBALS['wp_rest_server'];
$GLOBALS['wp_rest_server'] = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think these are needed, since it's just nulling out the server anyway. The test passes without these lines, since it's just testing rest_preload_api_request().

Suggested change
rest_get_server();
$rest_server = $GLOBALS['wp_rest_server'];
$GLOBALS['wp_rest_server'] = null;

Comment thread tests/phpunit/tests/rest-api.php Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change

The $GLOBALS['wp_rest_server'] = $rest_server; is not needed anymore

Comment thread tests/phpunit/tests/rest-api.php Outdated
Comment on lines 1129 to 1132
rest_get_server();

$rest_server = $GLOBALS['wp_rest_server'];
$GLOBALS['wp_rest_server'] = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
rest_get_server();
$rest_server = $GLOBALS['wp_rest_server'];
$GLOBALS['wp_rest_server'] = null;

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

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

3 participants