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

mondrake created an issue. See original summary.

bunty badgujar’s picture

Assigned: Unassigned » bunty badgujar
bunty badgujar’s picture

Status: Active » Needs review
StatusFileSize
new1.78 KB
mondrake’s picture

Status: Needs review » Needs work

Thank you @Bunty Badgujar.

Looking at the patch now, I think these method are superfluous. PHPUnit provides assertEquals and assertNotEquals. When these are used on comparing arrays, they do ensure same count of keys and equality of keys and values.

mondrake’s picture

Assigned: bunty badgujar » mondrake

On this.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.39 KB

Status: Needs review » Needs work

The last submitted patch, 6: 3144926-6.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new3.43 KB
new2.98 KB

Let's canonicalize.

mohrerao’s picture

Assigned: Unassigned » mohrerao
mohrerao’s picture

Assigned: mohrerao » Unassigned
StatusFileSize
new3.15 KB
new897 bytes

Rerolled patch #8

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

@mohrerao the reroll is wrong, it has lost one conversion.

ravi.shankar’s picture

Assigned: Unassigned » ravi.shankar
ravi.shankar’s picture

Assigned: ravi.shankar » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.43 KB

The last submitted patch, 10: 3144926-10.patch, failed testing. View results

joachim’s picture

+++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
@@ -338,7 +338,7 @@ protected function assertBigPipeResponseHeadersPresent() {
-    $this->assertSetsEqual(array_keys($expected_big_pipe_nojs_placeholders), array_map('rawurldecode', explode(' ', $this->drupalGetHeader('BigPipe-Test-No-Js-Placeholders'))));
+    $this->assertNotEqualsCanonicalizing(array_keys($expected_big_pipe_nojs_placeholders), array_map('rawurldecode', explode(' ', $this->drupalGetHeader('BigPipe-Test-No-Js-Placeholders'))));

We'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?

mondrake’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs issue summary update

Updated 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.

mondrake’s picture

Issue summary: View changes
StatusFileSize
new1.22 KB
new3.43 KB
mondrake’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: 3144926-17.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review

Anybody a clue about what should be tested here, really? Otherwise, I am inclined to say this is just dead code and suggest removing it.

longwave’s picture

Status: Needs review » Needs work

So 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:


   protected function assertSetsEqual(array $a, array $b) {
-    $a_set = $a;
-    sort($a_set);
-    $b_set = $b;
-    sort($b_set);
-    return $this->assertEqual($a_set, $b_set);
+    return count($a) == count($b) && !array_diff_assoc($a, $b);
   }

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.

longwave’s picture

So 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.

mondrake’s picture

Assigned: Unassigned » mondrake

Looks like BigPipePlaceholderTestCases were not updated at a certain point, and #21 allowed to let through a regression. On it.

mondrake’s picture

Assigned: mondrake » Unassigned
Issue tags: +Needs subsystem maintainer review
StatusFileSize
new6.58 KB

I 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Issue tags: -Deprecated assertions

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.