This issue is spun off from #2831274-390: Bring Media entity module to core as Media module, specifically this point of review:

there's new code to wait for stuff that's not being used. This might mean that they currently have random errors.

This is postponed on #2831274: Bring Media entity module to core as Media module.

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Postponed » Active
marcoscano’s picture

Status: Active » Needs review
Issue tags: +D8Media
StatusFileSize
new11.79 KB

Based on https://www.drupal.org/node/2846936 all instances of ::assertWaitOnAjaxRequest() were replaced by the new methods.

Is anything else needed here?

phenaproxima’s picture

Issue tags: -D8Media +Media Initiative

Re-tagging.

Status: Needs review » Needs work

The last submitted patch, 3: 2878113-3.patch, failed testing. View results

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new11.79 KB
new949 bytes

Status: Needs review » Needs work

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

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new11.84 KB
new1.06 KB

In MediaViewsWizardTest::testMediaRevisionWizard there is an AJAX call that doesn't add or remove any element from the page. I couldn't find a proper way of waiting for this call to finish without using ::assertWaitOnAjaxRequest(). Left a TODO in the code.

phenaproxima’s picture

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

I feel like waiting a set amount of time for the AJAX to be done is an almost guaranteed way to introduce random failures. Is there nothing we can wait on at all? Even if it's not element, surely we can wait on a JS condition of some sort?

vishal9619’s picture

StatusFileSize
new11.84 KB
marcoscano’s picture

@vishal9619 could you please point out the differences between your patch and the patch in #8?
Looks like it's the same file, renamed.

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new11.23 KB
new988 bytes

Once no DOM modification is done, perhaps any condition would be equivalent to what ::assertWaitOnAjaxRequest does?

We have removed 9 instances of ::assertWaitOnAjaxRequest, only this one is left. We are probably already reducing a lot the probabilities of random failures :)

Status: Needs review » Needs work

The last submitted patch, 12: 2878113-12.patch, failed testing. View results

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new11.19 KB
new2.34 KB

Re-roll needed

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Well...what can I say? Media's tests having been passing consistently ever since #2831274: Bring Media entity module to core as Media module landed, which seems to indicate that there are no random failures at present. And this patch improves the reliability of the tests even more. I can't think of any reason to delay this one further.

wim leers’s picture

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceFileTest.php
@@ -46,7 +46,8 @@ public function testMediaFileSource() {
-    $assert_session->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForButton('Remove');
+    $this->assertNotEmpty($result);

@@ -63,7 +64,8 @@ public function testMediaFileSource() {
-    $assert_session->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForButton('Remove');
+    $this->assertNotEmpty($result);

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php
@@ -60,7 +60,8 @@ public function testMediaImageSource() {
-    $assert_session->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForButton('Remove');
+    $this->assertNotEmpty($result);

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceTestBase.php
@@ -112,11 +112,13 @@ public function doTestCreateMediaType($media_type_id, $source_id, array $provide
-    $assert_session->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
+    $this->assertNotEmpty($result);
...
-      $assert_session->selectExists("field_map[{$provided_field}]");
+      $result = $assert_session->waitForElementVisible('css', 'select[name="field_map[' . $provided_field . ']"]');
+      $this->assertNotEmpty($result);

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaTypeCreationTest.php
@@ -13,24 +13,27 @@ class MediaTypeCreationTest extends MediaJavascriptTestBase {
-    $this->assertSession()->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
+    $this->assertNotEmpty($result);

@@ -38,51 +41,51 @@ public function testMediaTypeCreationFormWithDefaultField() {
-    $this->assertSession()->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
+    $this->assertNotEmpty($result);
...
-    $this->assertSession()->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
+    $this->assertNotEmpty($result);

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaUiJavascriptTest.php
@@ -120,7 +120,8 @@ public function testMediaTypes() {
-    $assert_session->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForElementVisible('css', 'fieldset[data-drupal-selector="edit-source-configuration"]');
+    $this->assertNotEmpty($result);

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaViewsWizardTest.php
@@ -27,7 +27,8 @@ public function testMediaWizard() {
-    $assert_session->assertWaitOnAjaxRequest();
+    $result = $assert_session->waitForElementVisible('css', 'select[data-drupal-selector="edit-show-type"]');
+    $this->assertNotEmpty($result);

This is waiting for the concrete result of the AJAX requests instead of just some AJAX request to complete.

Good hardening.

However, everything else is pure clean-up, theoretically out of scope. At committer's discretion to accept it or require it to be moved to a separate patch.

Looks good!

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

The hardenings look good. The cleanups I am not very concerned about here, they look fine too. Thanks for making the test more robust/explicit!

  • Gábor Hojtsy committed 54e77b6 on 8.4.x
    Issue #2878113 by marcoscano: Find possible random errors in Media's...

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Test always fails in case there is JS error in console. Wait for element visible also leads to fatal error some times.