Problem/Motivation

Random, inconsistent errors in the ckeditor5 FunctionalJavascript tests.

Testing Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest
..............E........                                           23 / 23 (100%)

Time: 07:06.351, Memory: 6.00 MB

There was 1 error:

1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testLinkManualDecorator with data set "unrestricted" (true)
Behat\Mink\Exception\ElementNotFoundException: Element matching css ".ck-balloon-panel_visible .ck-balloon-rotator__content > .ck.ck-link-actions" not found.

in https://www.drupal.org/pift-ci-job/2564452

10 Jan 2023 https://www.drupal.org/pift-ci-job/2564081
27 Mar 2023 https://www.drupal.org/pift-ci-job/2626370

Steps to reproduce

In a patch in another issue
I took screenshots just before the "balloon assertion" at line 1073.
Here's what a screenshot from a passing test looks like:
Yay!
In another patch I took screenshots at the same spot for failing tests.
That looks like this:
Booh!

Upon close inspection we see the differences:
The failing one has a different "balloon" (which is why the test fails) and an URL in the textfield below the actual media.
That textfield is actually the caption edit field, and seems to be default on in this test.

The test selects the media to be able to edit it by doing a

    $this->assertNotEmpty($drupalmedia = $assert_session->waitForElementVisible('css', '.ck-content .ck-widget.drupal-media'));
    $drupalmedia->click();

and seeing that '.ck-content .ck-widget.drupal-media' is the whole area surrounded by the blue border in the first image, there's a chance we click on the caption edit area.
When we do that the behaviour of the link-adding changes and doesn't follow the assertions in the test any more.

Proposed resolution

Toggle the Caption edit capability off, so we're sure we never add a link in there, instead of the wanted link on the media.

Remaining tasks

There are still 2 random test failures left that seem to stem from the inner bowels of CKEditor 5. To me they look like an upstream issue, but since I can't really pinpoint the root cause of those and seeing the fact that this patch drops the failure rate from about 10 in 1500 down to 6 in 45.000, I take that as a win.

User interface changes

API changes

Data model changes

Release notes snippet

Comments

jastraat created an issue. See original summary.

jastraat’s picture

Issue summary: View changes
wim leers’s picture

Title: Random test failures in ckeditor5\FunctionalJavascript\MediaTest » Random test failures in MediaTest::testLinkManualDecorator()
Issue tags: +JavaScript

Ugh! Thanks for reporting this! 🙏😊

wim leers’s picture

Title: Random test failures in MediaTest::testLinkManualDecorator() » Random test failures in MediaTest::testLinkManualDecorator() and MediaTest:: testEditableCaption()
quietone’s picture

Title: Random test failures in MediaTest::testLinkManualDecorator() and MediaTest:: testEditableCaption() » [random test failure] MediaTest::testLinkManualDecorator() and MediaTest:: testEditableCaption()
Issue summary: View changes
Issue tags: -JavaScript +JavaScript

Updating title per special issue titles.

Does this need two issues or is the same underlying problem?

jonathan1055’s picture

Issue summary: View changes

This happened on core 9.5 today. I know that we know this now, but adding the link for future reference
https://www.drupal.org/pift-ci-job/2626370

spokje’s picture

Assigned: Unassigned » spokje

Does this need two issues or is the same underlying problem?

@quietone in #6

I _think_ I found the problem with MediaTest::testLinkManualDecorator() and that seems unrelated to MediaTest:: testEditableCaption(), so repurposing this issue for the first failure and creating a new issue for the second one.

spokje’s picture

Title: [random test failure] MediaTest::testLinkManualDecorator() and MediaTest:: testEditableCaption() » [random test failure] MediaTest::testLinkManualDecorator()
Issue summary: View changes
Related issues: +#3366081: [random test failure] MediaTest:: testEditableCaption()
spokje’s picture

StatusFileSize
new67.73 KB

Let's first proof that running MediaTest::testLinkManualDecorator() alone, without any other tests in \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest still produces a random test failure.

Here's a patch that runs MediaTest::testLinkManualDecorator() and MediaTest::testLinkManualDecorator() alone 1500 times.

spokje’s picture

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

The actual fix should be back-portable (is that even a word?) to 9.4.x if needed, but since I'm needing to run the patches multiple times to proof both the "random" and the "failure" bit in random failure are solved, putting this to 11.x-dev, so I don't need to manually change the branch manually a gazillion times.

spokje’s picture

StatusFileSize
new67.73 KB
new68.43 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 do a write up in the IS to explain why this is the fix).

spokje’s picture

Issue summary: View changes
StatusFileSize
new53.91 KB
new54.31 KB
spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes
spokje’s picture

Hmmm,

promising, but the lack of a roll of dried tobacco leaves that people smoke, like a cigarette but bigger and without paper around it is disheartening.
At the very least the failure rate has dropped dramatically.

The failures in Sqlite are table locks, which most probably happen because I started 5 1500x runs at the same time.

The single test failure in PHP 8.1 & MySQL 5.7 is most probably cause by the fact that after I click the "Toggle caption off"-balloon-button (or rather, let TestBot click it 1500 times), I have no waiting period for the text-box to disappear and the "Drupal Media toolbar" being updated.

Let's add that wait and see what happens with the attached patches.

spokje’s picture

Issue summary: View changes
spokje’s picture

StatusFileSize
new53.25 KB
new52.19 KB

So there are 2 remaining random test failures:

  1. 1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testLinkManualDecorator with data set "unrestricted" (true)
    Behat\Mink\Exception\ElementNotFoundException: Element matching css ".ck-balloon-panel_visible .ck-balloon-rotator__content > .ck.ck-link-actions" not found.
    
    /var/www/html/vendor/behat/mink/src/WebAssert.php:418
    /var/www/html/core/modules/ckeditor5/tests/src/Traits/CKEditor5TestTrait.php:116
    /var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:284
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
      
  2. and

  3. 1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testLinkManualDecorator with data set "unrestricted" (true)
    Failed asserting that an object is not empty.
    
    /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
    /var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
    /var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:287
    /var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
      

Both are "wierd" (Well, wadda you expect from random JS failures...).

Looking at patch [3362864-60], which adds some screenshots and logging when those failures occur:

1. The screenshot shows that the link was _NOT_ created and the expected balloon is _NOT_ present.
CLUNK1
Weird stuff since it has passed all assertions on buttons being present, so the only thing I can come up with is that every once in a blue moon the actual CKEditor 5 (so not the Drupal code around it) fails to create a link.

2. The screenshot shows that the link was created and the expected balloon is present.
CLUNK2
However the contents of getEditorDataAsHtmlString is  , which seems "odd".

1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testLinkManualDecorator with data set "unrestricted" (true)
getEditorDataAsHtmlString is:  
Failed asserting that an object is not empty.

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:122
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:291
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

My gut feeling is that 1) could be an upstream problem and 2) being a result of 1).

I'm a bit unsure if it's worth to open a new follow-up issue on these, since the failure rate seems in the range of /shrug-js-tests-fail-once-every-blue-moon.

spokje’s picture

StatusFileSize
new1.05 KB

Seeing the fact that this change drops the failure rate from about 10 in 1500 down to 6 in 45.000, and that there's a (IMHO) valid root cause identified, I'm going to post the actual patch for review.

The decision if we need a follow-up for the remaining (very less frequent) test-failures remains open.

spokje’s picture

Assigned: spokje » Unassigned
Status: Active » Needs review
smustgrave’s picture

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

Think it if it significantly helps the fail rate that's better then what's currently there. I'm +1 for opening a follow up for the other failures (sticking to the agile thought) but will let the committer decide if it's worth it.

  • lauriii committed 3b6179f1 on 11.x
    Issue #3332456 by Spokje, jastraat: [random test failure] MediaTest::...

  • lauriii committed 049fb020 on 10.1.x
    Issue #3332456 by Spokje, jastraat: [random test failure] MediaTest::...

  • lauriii committed 10d3bb7a on 10.0.x
    Issue #3332456 by Spokje, jastraat: [random test failure] MediaTest::...

  • lauriii committed e3973cad on 9.5.x
    Issue #3332456 by Spokje, jastraat: [random test failure] MediaTest::...
lauriii’s picture

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

Committed 3b6179f and pushed to 11.x. Thanks! Cherry-picked all the way down to 9.5.x.

Status: Fixed » Closed (fixed)

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