Skip to content

Tests: Avoid repeated user creation in WP_Test_REST_Post_Meta_Fields - #13589

Open
SainathPoojary wants to merge 3 commits into
WordPress:trunkfrom
SainathPoojary:fix/66074-post-meta-fixtures
Open

SainathPoojary wants to merge 3 commits into
WordPress:trunkfrom
SainathPoojary:fix/66074-post-meta-fixtures

Conversation

@SainathPoojary

Copy link
Copy Markdown

Optimizes fixture setup in WP_Test_REST_Post_Meta_Fields by avoiding repeated editor user creation across individual tests.

Previously, grant_write_permission() called $factory->user->create() each time it was invoked (65+ calls across test methods and data provider iterations). This introduced unnecessary database insertions and teardown overhead for tests that only needed an authenticated editor user.

This change creates a shared editor user once in wpSetUpBeforeClass(), sets that user in grant_write_permission(), and cleans it up via self::delete_user() in wpTearDownAfterClass(). All 151 tests and 581 assertions remain unchanged and pass.

Performance

Measured locally across three consecutive runs comparing trunk to this branch:

Run Trunk Test Time (junit.xml) Trunk Wall Time Fix Test Time (junit.xml) Fix Wall Time
Run 1 2.386s 2.695s 1.829s 2.287s
Run 2 2.295s 2.612s 1.802s 2.219s
Run 3 2.242s 2.548s 1.850s 2.325s
Average 2.308s 2.618s 1.827s 2.277s

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 done 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.

@SainathPoojary
SainathPoojary marked this pull request as ready for review September 18, 2026 08:17
@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 sainathpoojary.

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

@SainathPoojary

Copy link
Copy Markdown
Author

I noticed a few of the CI test jobs are failing, so I spent some time investigating. I ran the tests locally, but they are passing for me without any issues.

I also checked trunk and a few other open PRs, and it looks like these similar failures are happening there as well. Since this is happening other places as well, it seems like these might be random test failures rather than something caused by these changes.

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