Problem/Motivation

As discoverd in #2832672: [PP-1] Upgrade jcalderonzumba/* for better test performance a test opening a dialog and then peforming actions within the opened dialog are at risk for random failure.

The random failure is caused by a dialog resize/reposition after content has been inserted. Currently there is no way to wait for this as this behavior is debounced.

Currently the random failures do not occur because the Mink Phantomjs driver waits an additional 100ms on each wait statement. However on upgrading the driver or switching to another driver (#2775653: JavascriptTests with webDriver) this problem will become relevant.

Proposed resolution

Either:
1. Provide a better way to assert the dialog has opened.
2. Remove the random failure factor for opening a dialog.

Steps to reproduce:

This issue improves the way we wait for a dialog to open. The reason is random failure and therefore difficult to reproduce.

To reproduce the random fail do the following:
- Apply the patch from #2832672: [PP-1] Upgrade jcalderonzumba/* for better test performance, this will make the random fail occur more often.
- Do not apply the patch from this issue.
- Run the test in views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php multiple times untill the test fails.
- See the excellent research in #2832672: [PP-1] Upgrade jcalderonzumba/* for better test performance by @tacituseu to see an explaination on the fails.

I have run the tests on multiple 25x runs locally and I got the fails frequently before applying this patch and no more after applying this patch.

Thanks @michielnugter for the patch. And tacituseu & droplet did a lot of researching on #2832672: [PP-1] Upgrade jcalderonzumba/* for better test performance. Please credit them also if we can.

Comments

michielnugter created an issue. See original summary.

michielnugter’s picture

StatusFileSize
new5.66 KB
new6.25 KB

Attached a convert from the original patch and used a trait, this is a fix using option 1. Not very happy yet with the way the dialog_test module is installed and checked on, don't know a better way yet.

Alternatives:
- Wait for #2844582: Move inline javascript in JSWebAssert into a separate javascript file to get in and move the assertion to JSWebAssert.

Questions:
- I kept the updated FilterDialogTest as a test for the change. Should this be split of later on?
- Is a separate test of the dialog required or does the FilterDialogTest suffice?

michielnugter’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2856047-2-25x.patch, failed testing.

michielnugter’s picture

Status: Needs work » Needs review
StatusFileSize
new5.66 KB
new6.25 KB

asserT instead of asser

Status: Needs review » Needs work

The last submitted patch, 5: 2856047-5-25x.patch, failed testing.

michielnugter’s picture

Status: Needs work » Needs review
StatusFileSize
new5.66 KB

self::$modules instead of $this->modules.

dawehner’s picture

+++ b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php
@@ -0,0 +1,23 @@
+    $this->assertTrue(in_array('dialog_test', self::$modules), 'The dialog_test module is required for this assertion.');

This condition feels more like an assert() assertion

michielnugter’s picture

StatusFileSize
new2.62 KB
new5.5 KB

I converted it to a assertArrayHasKey(), the assert() method really is deprecated right?

Some other clean-ups as well.

Status: Needs review » Needs work

The last submitted patch, 9: 2856047-9.patch, failed testing.

michielnugter’s picture

Status: Needs work » Needs review
StatusFileSize
new784 bytes
new5.45 KB

Right, wrong kind of assert.

I was thinking about this a little more and the current check can fail if the module is loaded on a base class because of the way the $modules array works. I therefore removed the check and added a hint in the phpdoc for this method. Is this acceptable?

droplet’s picture

Issue summary: View changes
Issue tags: +JavaScript

Tagging and add a credit message :P

I will review it this weekend or so if no one does it before me.

droplet’s picture

Issue summary: View changes
michielnugter’s picture

Issue summary: View changes

Thanks in advance @droplet. And very true on the credits for you and tacituseu, a lot of preliminary research went into the solution for this one.

balagan’s picture

I tried to triage this and review, but I just don't know how to reproduce this. Added Needs issue summary update tag, hoping someone adds steps to reproduce, or maybe droplet comes back and reviews this.

balagan’s picture

Issue summary: View changes
michielnugter’s picture

Issue summary: View changes
michielnugter’s picture

I updated the steps to reproduce.

cilefen’s picture

@balagan That's good work so far on triage. I could give you credit if you document the rest of the triage steps (even if brief). It is the only way to know if the triage has actually been completed. Here are some made-up examples of documented triage steps:

  • I tested the steps to reproduce and they did (or did not) work (so I am tagging it "Needs issue summary update").
  • I searched for duplicate issues but could not find any.
  • I checked the issue summary and it is accurate and up-to-date.
  • Etc...

Thank you!

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me. Do we need core/modules/system/tests/modules/dialog_test/js/dialog.debug.js in for all the dailogs?

.

jibran’s picture

Status: Reviewed & tested by the community » Needs review
martin107’s picture

StatusFileSize
new6.33 KB
new2.07 KB

A few small comments nothing of any consequence,

1) Since this issue was started, core now exclusively uses es6.js files which are transpiled into js

2) The variable dependency injection of the file was incorrect

This is the change.

-})(jQuery, Drupal, drupalSettings);
+})(jQuery, window, Drupal);
jibran’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: 2856047-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

GrandmaGlassesRopeMan’s picture

  1. +++ b/core/modules/system/tests/modules/dialog_test/js/dialog.debug.es6.js
    @@ -0,0 +1,23 @@
    +(function ($, window, Drupal) {
    

    Use arrow functions.

  2. +++ b/core/modules/system/tests/modules/dialog_test/js/dialog.debug.es6.js
    @@ -0,0 +1,23 @@
    +  'use strict';
    

    `use strict` not required here.

  3. +++ b/core/modules/system/tests/modules/dialog_test/js/dialog.debug.es6.js
    @@ -0,0 +1,23 @@
    +  $('#drupal-modal').on('dialogContentResize',  () => {
    

    Too many spaces.

tim.plunkett’s picture

+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
--- /dev/null
+++ b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php

+++ b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php
@@ -0,0 +1,23 @@
+  protected function waitForDialog($timeout = 10000) {

This adds a method that seems to be standalone.

+++ b/core/modules/system/tests/modules/dialog_test/dialog_test.module
@@ -0,0 +1,8 @@
+  $page['#attached']['library'][] = 'dialog_test/dialog_debug';

+++ b/core/modules/system/tests/modules/dialog_test/js/dialog.debug.js
@@ -0,0 +1,23 @@
+    Drupal.dialog_debug.has_open_dialog = true;

+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
@@ -11,10 +12,12 @@
-  public static $modules = ['node', 'views', 'views_ui'];
+  public static $modules = ['node', 'views', 'views_ui', 'dialog_test'];

+++ b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php
@@ -0,0 +1,23 @@
+    $condition = 'Drupal.dialog_debug.has_open_dialog == true';

However, it will silently do nothing if the `dialog_test` module is not installed.

I think the name is misleading. It only works for opening, not closing.
Furthermore, it does not account for a dialog that uses a fade effect, which assertWaitOnAjaxRequest() does protect against.

martin107’s picture

Assigned: Unassigned » martin107

I will spend sometime today resolving lint conflicts and will address the other issue while I am at it.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.49 KB
new6.28 KB

Fixed #26.

dawehner’s picture

+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/FilterCriteriaTest.php
@@ -11,10 +12,12 @@
+  public static $modules = ['node', 'views', 'views_ui', 'dialog_test'];

+++ b/core/tests/Drupal/FunctionalTests/AssertDialogTrait.php
@@ -0,0 +1,23 @@
+/**
+ * Provides methods for assertions in dialogs.
+ */
+trait AssertDialogTrait {

Can we add a test inside core, outside of the views module? This makes it for example less likely that we accidentally drop it.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

anavarre’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
kostyashupenko’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new6.24 KB

reroll

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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.

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.

xjm’s picture

Tagging so I can find this in the search; it's not a random test failure itself but it's about them.

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 200, following Review a patch or merge require as a guide.

# D10 version
D10 version needed
At this time we would need a D10.1.x patch or MR for this issue.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new4.28 KB
new6.07 KB

Rerolled for D10
Removed the es6 file from the test module.

The statusTest has changed some too so tried to address those.

catch’s picture

Are there any other tests that can use this? I think this might have been what dawehner was getting at in #31.

lendude’s picture

Status: Needs review » Needs work

I think a dedicated test for this trait/JS is what was asked for. Sounds like a good addition, currently if we were to remove the Views test, this functionality has no coverage.

smustgrave’s picture

Do you have an example of testing a trait?

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB
new7.21 KB

Something like this?

smustgrave’s picture

StatusFileSize
new512 bytes
new7.23 KB
lendude’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs follow-up

Nice, that looks great.

Code looks good, we are only updating 1 test here, should we do more here of should we open a follow-up to change more tests to use this?
I think landing this first is good, so marking RTBC, not making the follow up yet till others agree that would be the right way to handle this.

catch’s picture

Doing more in a follow-up seems good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 51: 2856047-51.patch, failed testing. View results

catch’s picture

Status: Needs work » Reviewed & tested by the community

Random failure..

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

Since this introduces changes intended to reduce random fails, this should have patches that customize drupalci.yml to run a single random-fail prone test several hundred times (possibly as many times as the test runner time limit allows). Include a version with and without the changes introduced here to compare the failure rate.

I also noticed that the solution here resembles something already in core specific to off canvas. Most of the lifting is done in these files:
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/sys...
https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/sys...

Perhaps the changes here can be integrated the off canvas ones, even if it's just having the traits in the same dir/namespace?

spokje’s picture

StatusFileSize
new1.62 KB
new8.85 KB

Since this introduces changes intended to reduce random fails, this should have patches that customize drupalci.yml to run a single random-fail prone test several hundred times (possibly as many times as the test runner time limit allows). Include a version with and without the changes introduced here to compare the failure rate.

Adding both those here, before we start work on (possible) integrating with the off canvas solution.

spokje’s picture

So what we've learned here is that FilterCriteriaTest is not broken (enough) to make any difference.

Not saying the approach in the patch for dialogs is wrong, just that it can't be tested with FilterCriteriaTest

catch’s picture

MediaLibraryTest::testButton() is a recently skipped random failure that checks for a dialog, so that might be a good one to try. #3351596: Skip Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest

spokje’s picture

StatusFileSize
new1.62 KB
spokje’s picture

StatusFileSize
new7.2 KB
spokje’s picture

Sadly also this one doesn't seem broken enough to be used for any proof.

catch’s picture

Maybe LayoutBuilderUiTest - just seen it come up:

.Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderUiTest
✗	
Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderUiTest
fail: [Other] Line 0 of sites/default/files/simpletest/phpunit-107.xml:
PHPUnit Test failed to complete; Error: PHPUnit 9.5.28 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderUiTest
F.S.                                                                4 / 4 (100%)

Time: 00:36.411, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderUiTest::testReloadWithNoSections
Error: cannot call methods on dialog prior to initialization; attempted to call method 'widget'
    at Function.error (http://php-apache-jenkins-drupal-

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

If we can't get it to fail out of 1500 runs, it suggests the recent instability of all these tests might not be related to the changes in this patch though.

spokje’s picture

StatusFileSize
new12.3 KB

If we can't get it to fail out of 1500 runs, it suggests the recent instability of all these tests might not be related to the changes in this patch though.

Even more: If we can't get MediaLibraryTest::testButton() to fail once in 1500 times when run on it's own, I fear it looks like the failure there has to do with concurrent running other tests?

nod_’s picture

Looks like it's failing pretty well :D

60-ish failures

nod_’s picture

got a potential fix for the issue in #65 over at #3350972: [random test failure] Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderUiTest::testReloadWithNoSections() which isn't quite an issue with the timing in tests.

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.

quietone’s picture

Issue tags: -Needs follow-up +Needs followup

Just fixing tag text.

herved’s picture

Perhaps a lead on how to reproduce this reliably: smaller screen height resolution seems to affect it a lot.

We have a huge suite of behat (selenium chromium) tests on a project at work. I wanted to change the resolution (from 1600x1200 to 1600x900) and noticed a lot of failures with modals. Traced it to the debounce (20ms) in Drupal.dialog.resetSize causing dialogs to bounce 2-3 times, then stumbled on this issue. In my case, the modal appears, selenium2 webdriver attempts to scroll in the modal to click on a link inside, but the modal repositions again before it can scroll and selenium throws a "move target out of bounds" error because the links is out of reach, still hidden below. (what a nightmare to debug).
I simply reverted to 1600x1200 for now, the modal seems more stable, way less repositioning for some reason.

herved’s picture

Does #3472624: Error: cannot call methods on dialog prior to initialization; attempted to call method 'option' solve this?
Specifically the change to execute debounce immediately/on leading edge in dialog.position.js:
const autoResize = debounce(resetSize, 20, true);

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.