Problem/Motivation

Testing Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest
F                                                                   1 / 1 (100%)

Time: 01:57.676, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest::testWidgetViews
"Loading grid view." not found
Failed asserting that a boolean is not empty.

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/var/www/html/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php:65
/var/www/html/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php:409
/var/www/html/core/modules/media_library/tests/src/FunctionalJavascript/WidgetViewsTest.php:118
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:726

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

1) Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest::testWidgetViews
WebDriver\Exception\CurlExec: Curl error thrown for http POST to http://chromedriver-jenkins-drupal-patches-187886:9515/session/73f6b5d5a73c8b7035b4362195d8782f/element/0.27412969624553574-76/click

Retries: 10 and last result:
{"sessionId":"73f6b5d5a73c8b7035b4362195d8782f","status":10,"value":{"message":"stale element reference: element is not attached to the page document\n  (Session info: headless chrome=106.0.5249.103)\n  (Driver info: chromedriver=106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249@{#569}),platform=Linux 4.9.0-0.bpo.6-amd64 x86_64)"}}

/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:198
/var/www/html/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php:146
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:125
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:234
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:241
/var/www/html/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:805
/var/www/html/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:729
/var/www/html/vendor/behat/mink/src/Element/NodeElement.php:185
/var/www/html/vendor/behat/mink/src/Element/TraversableElement.php:210
/var/www/html/core/modules/media_library/tests/src/FunctionalJavascript/WidgetViewsTest.php:123
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Steps to reproduce

In another galaxy issue, far, far away, I reproduced the first error and took screenshots when the assertion fails. That looks like this:
CLUNK1
So the assertion is done whilst the AJAX request hasn't finished yet.

The second failure can only happen for two reasons:
1. The element under test is removed from the DOM.
2. The page changed whilst after getting the element under test.

In this patch I took screenshots if there's a CurlExec is thrown. Those look like this:
CLUNK2

The select for Dog is still present, which leaves us with only option 2.

Upon closer inspection, the page actually does get (AJAX-)reloaded with the $page->pressButton('Apply filters'); just above our random failure point.

Proposed resolution

Add a $this->assertSession()->assertWaitOnAjaxRequest(); before both problematic code lines to make sure we're testing the page we're expecting to test.

For the second failure, we can now also change the waitFor(No)Text with pageText(Not)Contains, since the waiting is now, more reliable done with the assertWaitOnAjaxRequest()

Since both random failures are related in their cause and #5 proves they are both occuring with our (gazillion) test runs, I believe I can fly we can fix and test their "fixed-ness" in one go.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

I don't see what could possibly be wrong here.

I think this was just a random failure where this click literally didn't yield a result after even 10 seconds 🙈

  protected function switchToMediaLibraryGrid() {
    $this->getSession()->getPage()->clickLink('Grid');
    // Assert the display change is correctly announced for screen readers.
    $this->waitForText('Loading grid view.');

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.

spokje’s picture

Assigned: Unassigned » spokje
Issue tags: -JavaScript +JavaScript, +Random test failure
spokje’s picture

Issue tags: -JavaScript +JavaScript
StatusFileSize
new2.01 KB

Let's first proof that running WidgetViewsTest::testWidgetViews still produces random test failures.

Here's a patch that runs WidgetViewsTest::testWidgetViews 2000 times.

spokje’s picture

Title: Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest::testWidgetViews random fail » [random test failure] Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest::testWidgetViews random fail
Issue summary: View changes

So besides the SQLite SQLSTATE[HY000]: General error: 5 database is locked error, which I see happening a lot when doing loads of tests on a SQLite environment, we have a new contender besides the one in the current IS:

1) Drupal\Tests\media_library\FunctionalJavascript\WidgetViewsTest::testWidgetViews
WebDriver\Exception\CurlExec: Curl error thrown for http POST to http://chromedriver-jenkins-drupal-patches-187886:9515/session/73f6b5d5a73c8b7035b4362195d8782f/element/0.27412969624553574-76/click

Retries: 10 and last result:
{"sessionId":"73f6b5d5a73c8b7035b4362195d8782f","status":10,"value":{"message":"stale element reference: element is not attached to the page document\n  (Session info: headless chrome=106.0.5249.103)\n  (Driver info: chromedriver=106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249@{#569}),platform=Linux 4.9.0-0.bpo.6-amd64 x86_64)"}}

/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:198
/var/www/html/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php:146
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:125
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:234
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:241
/var/www/html/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:805
/var/www/html/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:729
/var/www/html/vendor/behat/mink/src/Element/NodeElement.php:185
/var/www/html/vendor/behat/mink/src/Element/TraversableElement.php:210
/var/www/html/core/modules/media_library/tests/src/FunctionalJavascript/WidgetViewsTest.php:123
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
spokje’s picture

spokje’s picture

StatusFileSize
new3.65 KB
spokje’s picture

StatusFileSize
new2.01 KB

The normal routine to prove a random failure is fixed is to run the failing patch and the patch with the fix at the same time, whilst the latter has to have ~8000 - 10.000 failure free runs to prove it's credibility.

So let's do that here, and double the amount of runs on our fix patch, since especially the first failure in the IS isn't too common anymore.

spokje’s picture

StatusFileSize
new1.64 KB

Thats 16 * 2000 = 32.000 runs without a test failure.

Good enough for me, here's the actual patch.

spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes
spokje’s picture

Status: Active » Needs review
spokje’s picture

Assigned: spokje » Unassigned
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Any improvement is better!

  • lauriii committed c1677724 on 11.x
    Issue #3317378 by Spokje, Wim Leers: [random test failure]...

  • lauriii committed f2abd5b9 on 10.1.x
    Issue #3317378 by Spokje, Wim Leers: [random test failure]...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed c167772 and pushed to 11.x. Cherry-picked to 10.1.x. Thanks!

The commit message 🤦‍♂️

spokje’s picture

nonCorrectEscapedAndTurnedIntoCamelCaseCommitMessagesAreGoingToBeBigIn2023

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.