Repository navigation
Load images that redirect - #26296
Conversation
Generated by 🚫 Danger |
jkmassel
left a comment
There was a problem hiding this comment.
The fix works. Both "More from WordPress.com Blog" thumbnails load in Reader, and the page layout picker still loads its previews (Jetpack, iOS 27.0 simulator).
One small thing in the new tests, as two suggestions to apply together: HTTPStubs.removeAllStubs() removes other suites' stubs too. Nothing breaks today, because no other suite in WordPressUIUnitTests uses stubs yet.
How this was checked: a scratch suite installed its own stub and made 100 downloads while UIImageViewNetworkingTests ran alongside it.
| Tests | Failed checks on first attempt |
|---|---|
| This PR | 4 (hidden by the test plan's automatic retry) |
| With the suggestions | 0 (two runs) |
The suggested file also passes make lint and is unchanged by swift format.
| FakeImageServer.install() | ||
| defer { HTTPStubs.removeAllStubs() } |
There was a problem hiding this comment.
HTTPStubs.removeAllStubs() removes every stub in the test process, not just this suite's.
What happens: .serialized only stops this suite's own tests from overlapping. Other suites in WordPressUIUnitTests still run at the same time. If one of them uses OHHTTPStubs, this defer can delete its stub partway through its test, and its request then goes to the real network.
Who is affected: nobody yet. No other suite in this target uses stubs today. The first one that does will be flaky.
Suggested fix: remove only the stub this download installed. This goes with the suggestion on install() below; apply both together.
How this was checked: we added a second scratch suite to the target that installs its own stub and removes only that one. Run next to this suite, its first attempt failed four checks because this defer deleted its stub; it only passed on the test plan's automatic retry. With both suggestions applied, the same run passed first time. See the review summary for the numbers.
| FakeImageServer.install() | |
| defer { HTTPStubs.removeAllStubs() } | |
| let fakeServer = FakeImageServer.install() | |
| defer { HTTPStubs.removeStub(fakeServer) } |
| static func install() { | ||
| stub(condition: isHost(host)) { request in |
There was a problem hiding this comment.
Return the stub's handle so download(_:) can remove just this stub. The body is a single expression, so no return is needed. Goes with the suggestion above.
| static func install() { | |
| stub(condition: isHost(host)) { request in | |
| static func install() -> HTTPStubsDescriptor { | |
| stub(condition: isHost(host)) { request in |
downloadImage rejected any image whose final URL differed from the requested one, so images behind a redirect, such as files.wordpress.com addresses in Reader related posts, never loaded. The check existed for mShots, which redirects to a placeholder while it generates a screenshot. Reject only that placeholder, so the layout and site design pickers keep polling, and stop them from polling redirected thumbnails forever.
f1a30bd to
aba4311
Compare
Description
Fixes https://linear.app/a8c/issue/CMM-2595
To reproduce the issue: in Reader, open "Stop Paying Extra to Keep Your Site Safe" (WordPress.com Blog) and scroll to "More from WordPress.com Blog". The two thumbnails stay gray.
Their images are on
en-blog.files.wordpress.com, which redirects toen.blog.wordpress.com/wp-content/uploads/....downloadImagerejected any image whose final URL was not the requested one, so every redirected image failed, in Reader and anywhere else that uses it.Why the URL check exists
a3c9668 (#15252, 2020) added the check so
CollapsableHeaderCollectionViewCellcan poll mShots previews. While mShots generates a screenshot it answers 307 tohttps://s0.wp.com/mshots/v1/default, a placeholder GIF; Calypso documents the same contract inpackages/components/src/site-thumbnail/use-mshots-img.tsx. The cell retries every second onurlMismatchuntil it gets the screenshot. Only this cell handles that error, for two screens throughCategorySectionTableViewCell: the site design picker, whose thumbnails come from mShots, and the page layout picker, whose thumbnails come from mShots for sites reachable through WordPress.com and otherwise fromheadstartdata.files.wordpress.com, which redirects with 302 like the Reader images.Removing the check would cache the placeholder under the real URL and stop the retries. So
downloadImagenow rejects only a final URL whose path is/mshots/v1/default, andurlMismatchbecomesmShotsPlaceholder, which says what it now means.This also fixes the pickers. A thumbnail behind a redirect never loaded there, and the cell requested it again every second while it was on screen.
Testing instructions
I can't make mShots answer "not ready" on demand, so I tested the pickers' retry path with a local server standing in for it: "not ready" three times, then the image.