Working on #3138078: [D9.3 beta - w/c Nov 8, 2021] Add a 'void' return typehint to custom assert* methods, it looks like BigPipeTest::assertSetsEqual is not an assertion at all - it is just returning a value.
This is misleading and actually misused since in no case the value returned by the method is used further (no assignments, and not used as argument for other methods).
Converting to
/**
* Asserts whether arrays A and B are equal, when treated as sets.
*/
- protected function assertSetsEqual(array $a, array $b) {
- return count($a) == count($b) && !array_diff_assoc($a, $b);
+ protected function assertSetsEqual(array $a, array $b): void {
+ $this->assertTrue(count($a) == count($b) && !array_diff_assoc($a, $b));
}
/**
leads to failure of the assertion, so there may be underlying bugs.
Proposed resolution
Use assertEqualsCanonicalizing instead, that sorts both expected and actual arrays by keys before comparing them.
Comments
Comment #2
bunty badgujar commentedComment #3
bunty badgujar commentedComment #4
mondrakeThank you @Bunty Badgujar.
Looking at the patch now, I think these method are superfluous. PHPUnit provides
assertEqualsandassertNotEquals. When these are used on comparing arrays, they do ensure same count of keys and equality of keys and values.Comment #5
mondrakeOn this.
Comment #6
mondrakeComment #8
mondrakeLet's canonicalize.
Comment #9
mohrerao commentedComment #10
mohrerao commentedRerolled patch #8
Comment #11
mondrake@mohrerao the reroll is wrong, it has lost one conversion.
Comment #12
ravi.shankar commentedComment #13
ravi.shankar commentedComment #15
joachim commentedWe've changed the assertion from saying things are equal to saying they're not equal...
Was the test wrong before? If so, could the issue summary be updated to explain how?
Comment #16
mondrakeUpdated IS.
You are right I think, we probably shoud not change to negative assertion. I am afraid this will reveal a bug, though. Working on an updated patch.
Comment #17
mondrakeComment #18
mondrakeComment #20
mondrakeAnybody a clue about what should be tested here, really? Otherwise, I am inclined to say this is just dead code and suggest removing it.
Comment #21
longwaveSo doing some git and d.o archaeology leads us to #2469431: BigPipe for auth users: first send+render the cheap parts of the page, then the expensive parts where this test was first introduced. A refactor in comment #244 accidentally removed the assertion from
assertSetsEqual(), as per the interdiff:Therefore it seems the intent was to do what
assertEqualsCanonicalizing()now does, and switching to that as in #17 seems the right thing to do.Next step is to figure out why one of the tests is now failing, and fix that.
Comment #22
longwaveSo there are multiple issues that have touched that test since it was first introduced, some of the ones that could have made a difference here are:
#2678568: Ensure good UX & DX even when A) rendering of placeholder fails, B) some response event subscriber fails
#2712935: Messages are not rendered last, meaning those messages set within placeholders only appear on the next request
#2657684: Refactor BigPipe internals to allow a contrib module to extend BigPipe with the ability to stream anonymous responses and prime Page Cache for subsequent visits
I guess if all else fails we can roll back to older versions of core, fix the test assertion there, and see if we can figure out whether this has always been broken or if one of those issues broke it. This would normally be a good use of git bisect except that halfway through we change from WebTestBase to BrowserTestBase.
Comment #23
mondrakeLooks like BigPipePlaceholderTestCases were not updated at a certain point, and #21 allowed to let through a regression. On it.
Comment #24
mondrakeI tried to update the test cases, but there seems to be no straightforward fix here. We need someone with deeper knowledge of this subsystem to review, I guess.
Posting a patch with my latest attempts so far, we should get one fail.
Comment #27
mondrake