Skip to content

Commit 39b28b0

Browse files
author
Pratik Nawkar
committed
Moderate speculation eagerness when page + object cache; Site Health transient, PHPUnit isolation
1 parent e8dff07 commit 39b28b0

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

tests/phpunit/includes/abstract-testcase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ public function set_up() {
135135
if ( $wp_rewrite->permalink_structure ) {
136136
$this->set_permalink_structure( '' );
137137
}
138+
139+
/*
140+
* Site Health stores page cache probe results in this transient. When a persistent object cache is used
141+
* (common in CI), it would otherwise change the default resolved eagerness for unrelated tests.
142+
*
143+
* @ticket 64066
144+
*/
145+
delete_transient( 'health_check_page_cache_detail' );
138146
}
139147

140148
$this->start_transaction();

tests/phpunit/tests/speculative-loading/wpGetSpeculationRulesConfiguration.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,31 @@ class Tests_Speculative_Loading_wpGetSpeculationRulesConfiguration extends WP_Un
1919
*/
2020
private $initial_using_ext_object_cache;
2121

22+
/**
23+
* getenv( 'WP_ENVIRONMENT_TYPE' ) at the start of the test, for restoration in tear_down().
24+
*
25+
* @var string|false
26+
*/
27+
private $wp_environment_type_env_before_test;
28+
2229
public function set_up() {
2330
parent::set_up();
2431

25-
$this->initial_using_ext_object_cache = wp_using_ext_object_cache();
32+
$this->initial_using_ext_object_cache = wp_using_ext_object_cache();
33+
$this->wp_environment_type_env_before_test = getenv( 'WP_ENVIRONMENT_TYPE' );
2634

2735
update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
2836
}
2937

3038
public function tear_down() {
3139
wp_using_ext_object_cache( $this->initial_using_ext_object_cache );
32-
delete_transient( 'health_check_page_cache_detail' );
33-
// Reset for following tests: wp_get_environment_type() keeps a static when WP_RUN_CORE_TESTS is defined.
34-
putenv( 'WP_ENVIRONMENT_TYPE=production' );
40+
41+
if ( false !== $this->wp_environment_type_env_before_test && '' !== $this->wp_environment_type_env_before_test ) {
42+
putenv( 'WP_ENVIRONMENT_TYPE=' . $this->wp_environment_type_env_before_test );
43+
} else {
44+
putenv( 'WP_ENVIRONMENT_TYPE' );
45+
}
46+
3547
parent::tear_down();
3648
}
3749

0 commit comments

Comments
 (0)