Skip to content

Tests: Delete the network created by the wp_prime_network_option_caches() tests. - #16145

Open
ekamran wants to merge 1 commit into
WordPress:trunkfrom
ekamran:shifteq/66755-network-option-caches-network
Open

ekamran wants to merge 1 commit into
WordPress:trunkfrom
ekamran:shifteq/66755-network-option-caches-network

Conversation

@ekamran

@ekamran ekamran commented Nov 21, 2026

Copy link
Copy Markdown

On multisite, Tests_Option_WpPrimeNetworkOptionCaches::wpSetUpBeforeClass() creates a second network (wordpress.org, path /), and the class never deletes it. Data from wpSetUpBeforeClass() is committed outside the per-test transaction, and _delete_all_data() does not clear wp_site or wp_sitemeta, so the network stays for the rest of the run. Network tests that run later then find it: Tests_Multisite_wpNetworkQuery gets an extra network in its results, and Tests_Multisite_Bootstrap::test_get_network_by_path() matches the leaked wordpress.org/ network. In the default order option/ runs after multisite/, so this only shows in other orders.

The other classes that create networks in wpSetUpBeforeClass() delete them again, such as Tests_Multisite_wpNetworkQuery::wpTearDownAfterClass().

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

What changes

  • A new wpTearDownAfterClass() deletes the network's sitemeta and site rows on multisite, with the same queries as Tests_Multisite_wpNetworkQuery.

Testing

Locally with PHP 8.4.27, MySQL 9.7.4 and PHPUnit 9.6.39 on multisite:

  • With the config below, which runs option/wpPrimeNetworkOptionCaches.php and then three multisite network test files, vendor/bin/phpunit -c pair.xml --filter 'Tests_Option_WpPrimeNetworkOptionCaches|Tests_Multisite_wpNetworkQuery|test_get_network_by_path|test_get_main_network_id_after_network_delete': 15 failures on trunk (9 in Tests_Multisite_wpNetworkQuery, 5 data sets of the two test_get_network_by_path tests in Tests_Multisite_Bootstrap, and Tests_Multisite_Network::test_get_main_network_id_after_network_delete()), OK (57 tests, 126 assertions) with this change.
  • The same network tests without the option tests, vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Multisite_wpNetworkQuery|test_get_network_by_path|test_get_main_network_id_after_network_delete': OK (52 tests, 90 assertions) before and after.
  • vendor/bin/phpunit --filter 'Tests_Option_WpPrimeNetworkOptionCaches::': OK (3 tests, 25 assertions) on single site and OK (5 tests, 36 assertions) with -c tests/phpunit/multisite.xml, before and after.
  • Found in full-suite runs with -c tests/phpunit/multisite.xml --testsuite default --order-by=random (seeds 101 and 202).
  • PHPCS reports nothing on the changed file.
<phpunit bootstrap="tests/phpunit/includes/bootstrap.php" backupGlobals="false" convertErrorsToExceptions="true" convertWarningsToExceptions="true" convertNoticesToExceptions="true" convertDeprecationsToExceptions="true">
	<testsuites>
		<testsuite name="pair">
			<file>tests/phpunit/tests/option/wpPrimeNetworkOptionCaches.php</file>
			<file>tests/phpunit/tests/multisite/wpNetworkQuery.php</file>
			<file>tests/phpunit/tests/multisite/bootstrap.php</file>
			<file>tests/phpunit/tests/multisite/network.php</file>
		</testsuite>
	</testsuites>
	<php>
		<const name="WP_RUN_CORE_TESTS" value="1" />
		<const name="WP_TESTS_MULTISITE" value="1" />
	</php>
</phpunit>

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: Investigation, code, local testing and PR wording. I reviewed the reasoning, the code and the test results, and I take responsibility for the contribution.


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

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

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

Props ekamran.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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