Opened 5 hours ago
Last modified 5 hours ago
#66159 new defect (bug)
Tests: test_insert_cropped_attachment() passes a URL where WP_Site_Icon::insert_attachment() expects a path, and waits four minutes when WP_TESTS_DOMAIN has a port
| Reported by: | lancewillett | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Build/Test Tools | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | tests |
Description
Tests_WP_Site_Icon::test_insert_cropped_attachment() builds $cropped from the attachment GUID:
$parent_url = get_post( $attachment_id )->guid; $cropped = str_replace( wp_basename( $parent_url ), 'cropped-test-image.jpg', $parent_url ); $cropped_id = $this->wp_site_icon->insert_attachment( $object, $cropped );
WP_Site_Icon::insert_attachment() expects a file path. That is what wp_ajax_crop_image() gives it, via wp_crop_image(). It passes $cropped to wp_generate_attachment_metadata(), whose image functions open the value as a file. Given a URL, PHP opens it over HTTP.
With the default WP_TESTS_DOMAIN of example.org, port 80 answers in under a second, so the test passes quickly and the mistake is invisible. The two GitHub Actions jobs that run with tests-domain: example.org:8889 in phpunit-tests.yml open http://example.org:8889/wp-content/uploads/.../cropped-test-image.jpg four times. Each open waits the full default_socket_timeout of 60 seconds, because nothing listens on that port. The test takes 240 seconds on every run of those two jobs.
Measured locally on trunk at [63792], multisite config, PHP 8.3:
WP_TESTS_DOMAIN | test duration |
|---|---|
example.org | 0.51s |
example.org:8889 | 240.34s |
example.org:8889 with default_socket_timeout=2 | 8.17s |
On CI, PHP 8.4 / MySQL 8.4 multisite example.org:8889 is the slowest job in the matrix and the one most often killed at the 30-minute timeout-minutes limit. On the trunk run for [63792], job 106736909855 goes silent for exactly four minutes between tests 12,980 and 13,039, then hits the limit and is rerun.
The fix is in the test: write a real cropped file into the uploads directory (a copy of the parent image is enough) and pass its path, which is what the production code path provides. No change to WP_Site_Icon is needed.
Change History (1)
This ticket was mentioned in PR #13661 on WordPress/wordpress-develop by @lancewillett.
5 hours ago
#1
- Keywords has-patch has-unit-tests added
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
What
Tests_WP_Site_Icon::test_insert_cropped_attachment()built the cropped file name from the attachment GUID and passed that URL toWP_Site_Icon::insert_attachment(). That method expects a file path, which is whatwp_ajax_crop_image()gives it viawp_crop_image(). It hands the value towp_generate_attachment_metadata(), whose image functions open it as a file, so a URL is opened over HTTP.This change copies the parent image to the cropped file name in the uploads directory and passes that path.
Why
With the default
WP_TESTS_DOMAINofexample.org, port 80 answers in under a second, so the test passed quickly and the mistake was invisible. The two jobs that run withtests-domain: example.org:8889openhttp://example.org:8889/wp-content/uploads/.../cropped-test-image.jpgfour times, and each open waits the fulldefault_socket_timeoutof 60 seconds because nothing listens on that port. The test takes 240 seconds on every run of those two jobs, andPHP 8.4 / MySQL 8.4 multisite example.org:8889is the job most often killed at the 30-minute limit. On the trunk run for [https://core.trac.wordpress.org/changeset/63792 [63792]], job 106736909855 went silent for exactly four minutes in this test, then hit the limit and was rerun.Measured locally, multisite config, PHP 8.3:
WP_TESTS_DOMAINexample.orgexample.org:8889example.org:8889,default_socket_timeout=2No change to
WP_Site_Icon.🤖 Generated with Claude Code