#34087 closed defect (bug) (fixed)
Tests_Image_Intermediate_Size::test_get_intermediate_sizes_by_array_zero_width fails when the random value is 201
Reported by: | jorbin | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | 2nd-opinion |
Focuses: | Cc: |
Description
This is an intermittent test failure. I'm not sure if it fails due to 201 finding an underlying bug or there being a bug in the test code.
Attachments (1)
Change History (9)
#2
@
9 years ago
- Keywords 2nd-opinion added
I spent a few minutes with this. I don't understand the size-selection logic well enough to fully grok what's happening. But it's roughly this:
- The test in question is meant to demonstrate that
image_get_intermediate_size()
will skip the 'false-height' image size. - In the case where 'false-height' is defined with a height of 201, 'false-height' is not skipped.
- The original image being cropped, waffles.jpg, is 600x400. This is close enough that attempting to crop it into a height of 201 will maintain a width of 300.
- 300 is within the 1px margin of error that
image_get_intermediate_size()
uses to determine whether a potential size has a different aspect ratio from an available image size. - So 300x201 ends up being a viable image size, not a "false" height image size.
See https://core.trac.wordpress.org/ticket/17626#comment:32 and the following few comments.
I'm not sure whether this is a bug in the function. At a glance, I'd say that if we are OK with the general principle of allowing a 1px margin of error for aspect ratio equivalence, then the function is probably performing as expected. That makes it a bug in the test: the 300x201 aspect ratio does not match "a single dimention" [sic], it in fact matches both dimensions.
Using random number/string generators in unit tests is a pretty bad idea. In some cases, it may show us edge case bugs, but that's not worth the trade-off of having tests that act differently each time you run them. This test probably ought to be rewritten to be hardcoded with a number that is just large enough to cause the aspect ratio check to fail: 202.
#3
@
9 years ago
Very quick follow-up: I think that the failure of this test is causing Tests_Media::test_add_image_size()
to fail. (Hooray for globals!) The test suite ought to remove custom image sizes during tearDown()
or setUp()
.
#4
@
9 years ago
On the basis of my analysis above, I'm going to split the current test into two: one that does what the original test was supposed to do (with a value of 202), and one that demonstrates the off-by-1 check for aspect ratios. If this seems wrong to anyone, you can reopen the ticket and tell me so :)
#5
@
9 years ago
- Owner set to boonebgorges
- Resolution set to fixed
- Status changed from new to closed
In 34775:
The above patch uses a data provider instead of random to help demonstrate this failure.