[random test failure] \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testViewMode random fail

Created on 17 June 2023, over 1 year ago
Updated 19 June 2023, over 1 year ago

Problem/Motivation

A new contender on the random test failure stage is:

1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testViewMode with data set "without alignment" (false)
Behat\Mink\Exception\ElementNotFoundException: Element matching css "article.media--view-mode-_2222" not found.

/var/www/html/vendor/behat/mink/src/WebAssert.php:418
/var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:1554
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Seen in the QA jobs ( https://www.drupal.org/node/3060/qa ):
https://www.drupal.org/pift-ci-job/2693933
https://www.drupal.org/pift-ci-job/2694177

Whilst researching this, another, less frequent random fail in the same method was detected:

1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testViewMode with data set "without alignment" (false)
Behat\Mink\Exception\ElementNotFoundException: Element matching css "article.media--view-mode-view-mode-1" not found.

/var/www/html/vendor/behat/mink/src/WebAssert.php:418
/var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:361
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

https://www.drupal.org/pift-ci-job/2694785

Since both random fails occur in the same test method, it's hard/impossible to get ~10.000 clean runs, needed to proof the patch is working, when solving only one of them.
Let's solve them both in this issue.

Steps to reproduce

The failing $assert_session->elementExists('css', 'article.media--view-mode-view-mode-X');s seem to not have enough waiting time before them to have the switching of the media view mode fully processed.

Note that there are 4 of these assertions and only 2 fail randomly. The ones that _don't_ fail randomly have a wait-assert of somekind in the lines before them.

Since there seem to be no visual nor non-visual (think HTML attribute change somewhere) change, there's no "nice way" to wait for the switching of the media view mode being fully processed.

Although I'm not a big fan of whacking waitForElement() on tests, it seems to me this is the only way to remove these random fails.

Proposed resolution

Replace the two randomly failing $assert_session->elementExists('css', 'article.media--view-mode-view-mode-X');s with similiar $assert_session->waitForElement('css', 'article.media--view-mode-X')s.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

11.0 🔥

Component
PHPUnit 

Last updated about 10 hours ago

Created by

🇳🇱Netherlands spokje

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024