From 033d43e7d96522012e7a16f537d09004b096ff3b Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 1 Sep 2022 17:04:52 +0000 Subject: [PATCH] Site Health: Refine persistent object cache check tests. This changeset makes these tests more reliable by having them less affected by external environment factors, fixing occasional failures. See #56040. git-svn-id: https://develop.svn.wordpress.org/trunk@54053 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/site-health.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/site-health.php b/tests/phpunit/tests/site-health.php index ed3981c022..7aded7ad61 100644 --- a/tests/phpunit/tests/site-health.php +++ b/tests/phpunit/tests/site-health.php @@ -362,9 +362,25 @@ class Tests_Site_Health extends WP_UnitTestCase { * @group ms-excluded * @ticket 56040 */ - public function test_object_cache_default_thresholds() { + public function test_object_cache_default_thresholds_non_multisite() { $wp_site_health = new WP_Site_Health(); + // Set thresholds so high they should never be exceeded. + add_filter( + 'site_status_persistent_object_cache_thresholds', + function() { + return array( + 'alloptions_count' => PHP_INT_MAX, + 'alloptions_bytes' => PHP_INT_MAX, + 'comments_count' => PHP_INT_MAX, + 'options_count' => PHP_INT_MAX, + 'posts_count' => PHP_INT_MAX, + 'terms_count' => PHP_INT_MAX, + 'users_count' => PHP_INT_MAX, + ); + } + ); + $this->assertFalse( $wp_site_health->should_suggest_persistent_object_cache() ); @@ -387,11 +403,16 @@ class Tests_Site_Health extends WP_UnitTestCase { */ public function test_object_cache_thresholds_check_can_be_bypassed() { $wp_site_health = new WP_Site_Health(); - add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' ); + add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' ); $this->assertTrue( $wp_site_health->should_suggest_persistent_object_cache() ); + + add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_false', 11 ); + $this->assertFalse( + $wp_site_health->should_suggest_persistent_object_cache() + ); } /**