Skip to content

Commit cac149e

Browse files
Make asset_cache_purged test deterministic instead of relying on page-visit side effect
Enabling the cache path was already explicit via a real settings save, but materializing the underlying asset-parent post depended on a subsequent admin page load's Assets::update_asset_paths() side effect — a timing-sensitive path that flaked once under CI load (passed on retry). Create the post directly instead, removing that dependency entirely.
1 parent 5d0f0ac commit cac149e

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

tests/e2e/cache-analytics.spec.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,31 @@ test.describe( 'Non-media cache analytics', () => {
109109
// rest_purge_all() resolves the `parent` param via
110110
// Assets::get_param(), which is only ever populated by
111111
// activate_parent() — an in-memory (non-persisted) call made during
112-
// Assets::activate_parents() for paths configured 'on' in settings.
113-
// create_asset_parent() alone (used by the other tests here, which
114-
// go through get_asset_parent() — a real, DB-backed lookup instead)
115-
// isn't enough for this specific endpoint. None of the plugin's
116-
// default non-media paths (WP core, active theme, plugins, uploads)
117-
// are active out of the box — on a fresh install this path setting
118-
// defaults to off — so explicitly enable it the same way a real
119-
// settings-page submission would via `Admin::save_settings()`.
112+
// Assets::activate_parents() for paths configured 'on' in settings,
113+
// AND only for a path that already has a real asset-parent post.
114+
// None of the plugin's default non-media paths (WP core, active
115+
// theme, plugins, uploads) are active out of the box — on a fresh
116+
// install this path setting defaults to off — so explicitly enable
117+
// it the same way a real settings-page submission would via
118+
// `Admin::save_settings()`, and create the underlying post directly
119+
// rather than relying on a subsequent admin page load's side effect
120+
// (`Assets::update_asset_paths()`) to materialize it, which is a
121+
// timing-sensitive path that has flaked under CI load.
120122
const realCachePoint = 'wp-content/uploads/';
121123
wpEvalFile( `
122124
$admin = get_plugin_instance()->get_component( 'admin' );
123125
$method = new \\ReflectionMethod( $admin, 'save_settings' );
124126
$method->setAccessible( true );
125127
$method->invoke( $admin, 'cache', array( 'wp_content' => 'on' ) );
128+
129+
$assets = get_plugin_instance()->get_component( 'assets' );
130+
$uploads = wp_get_upload_dir();
131+
$url = trailingslashit( $uploads['baseurl'] );
132+
if ( null === $assets->get_asset_parent( $url ) ) {
133+
$assets->create_asset_parent( $url, 0 );
134+
}
126135
` );
127136

128-
// `Assets::update_asset_paths()` — which creates the underlying
129-
// asset-parent post for a newly-enabled path — only runs on a real,
130-
// logged-in, non-REST admin request, so this visit is what actually
131-
// materializes the cache point before the REST purge call below.
132137
await admin.visitAdminPage( 'admin.php', 'page=cloudinary' );
133138
const { restBase, nonce } = await getRestContext( page );
134139

0 commit comments

Comments
 (0)