Problem/Motivation

Core's JS testing is notoriously prone random fail. This gets worse with upcoming changes to behat/mink-selenium2-driver - specifically https://github.com/minkphp/MinkSelenium2Driver/pull/322 - as we're no longer waiting as much.

This patch aims to make JS tests more reliable by discovering places where our waits can be improved and improving them.

Proposed resolution

Run mutiple JS tests on many environments and fix the random fails.

Remaining tasks

We still need to address #3066447: [random test failure] Random failures building media library form after uploading image (WidgetUploadTest) but given the other improvements here I think going forward is worth it.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

N/a

CommentFileSizeAuthor
#48 3174928-2-47.patch17.73 KBalexpott
#43 3174928-2-44-fixes-plus-repeat-js-testing.patch19.38 KBalexpott
#42 3174928-2-43-repeat-JS-testing.patch1.64 KBalexpott
#40 3174928-40.patch32.47 KBalexpott
#40 38-40-interdiff.txt2.01 KBalexpott
#38 3174928-38.patch32.04 KBalexpott
#38 36-38-interdiff.txt1.36 KBalexpott
#36 3174928-36.patch31.82 KBalexpott
#36 35-36-interdiff.txt2.4 KBalexpott
#35 3174928-35.patch29.93 KBalexpott
#34 32-33-interdiff.txt1.57 KBalexpott
#32 3174928-32.patch28.73 KBalexpott
#32 31-32-interdiff.txt3.14 KBalexpott
#31 3174928-31.patch25.05 KBalexpott
#31 30-31-interdiff.txt822 bytesalexpott
#30 3174928-30.patch25.05 KBalexpott
#30 29-30-interdiff.txt1.16 KBalexpott
#29 3174928-29.patch23.89 KBalexpott
#29 28-29-interdiff.txt903 bytesalexpott
#28 3174928-28.patch23.85 KBalexpott
#28 25-28-interdiff.txt3.31 KBalexpott
#27 3174928-27.patch23.79 KBalexpott
#25 3174928-25.patch21.21 KBalexpott
#25 24-25-interdiff.txt683 bytesalexpott
#24 3174928-24.patch20.84 KBalexpott
#24 20-24-interdiff.txt1.65 KBalexpott
#20 3174928-20.patch19.19 KBalexpott
#20 18-20-interdiff.txt940 bytesalexpott
#18 3174928-18.patch19.2 KBalexpott
#17 3174928-17.patch19.86 KBalexpott
#17 15-17-interdiff.txt1.41 KBalexpott
#15 3174928-15.patch19.46 KBalexpott
#15 10-15-interdiff.txt6.37 KBalexpott
#10 3174928-10.patch13.1 KBalexpott
#10 7-10-interdiff.txt2.79 KBalexpott
#7 3174928-7.patch11.36 KBalexpott
#7 6-7-interdiff.txt671 bytesalexpott
#6 3174928-6.patch11.36 KBalexpott
#6 4-6-interdiff.txt2.51 KBalexpott
#4 3174928-4.patch10.64 KBalexpott
#4 2-4-interdiff.txt3.78 KBalexpott
#2 3174928-2.patch6.85 KBalexpott

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new6.85 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3174928-2.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new3.78 KB
new10.64 KB

Some more fixes.

Status: Needs review » Needs work

The last submitted patch, 4: 3174928-4.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new2.51 KB
new11.36 KB

Wow just found out that in webdriver we can set an implicit wait for things. This I think is a great idea that will make our tests way more reliable.

alexpott’s picture

StatusFileSize
new671 bytes
new11.36 KB

#6 is gonna fail lets bump the wait to 1second.

alexpott’s picture

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

alexpott’s picture

StatusFileSize
new2.79 KB
new13.1 KB

Bump the timeout to 2secs (note the wait timeout is 10secs) and fix a few more colons.

The last submitted patch, 7: 3174928-7.patch, failed testing. View results

andypost’s picture

Issue tags: +PHP 8.0
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
@@ -37,7 +37,7 @@ function isAjaxing(instance) {
-      }());
+      }())

Looks this changes needs CR

Status: Needs review » Needs work

The last submitted patch, 10: 3174928-10.patch, failed testing. View results

alexpott’s picture

@andypost it's likely that these changes won't be required - just recommended - see https://github.com/minkphp/MinkSelenium2Driver/issues/324#issuecomment-7... and https://github.com/minkphp/MinkSelenium2Driver/pull/325

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new6.37 KB
new19.46 KB

Status: Needs review » Needs work

The last submitted patch, 15: 3174928-15.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB
new19.86 KB
alexpott’s picture

StatusFileSize
new19.2 KB

So let's see if the implicit wait is actually doing anything...

Status: Needs review » Needs work

The last submitted patch, 18: 3174928-18.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new940 bytes
new19.19 KB

The last submitted patch, 18: 3174928-18.patch, failed testing. View results

The last submitted patch, 15: 3174928-15.patch, failed testing. View results

andypost’s picture

Looks pgsql needs more then 200ms timeouts to pass fragile quick edit test

alexpott’s picture

StatusFileSize
new1.65 KB
new20.84 KB

Moving stuff around to see if we can make the quickedit test more reliable. Nearly all of our problems are caused by assertWaitOnAjaxRequest

alexpott’s picture

StatusFileSize
new683 bytes
new21.21 KB
alexpott’s picture

Ignore the Postgres 9.5 test in #25 D9 does not support that version of Postgres.

alexpott’s picture

StatusFileSize
new23.79 KB

Let's get rid of all assertWaitOnAjax... in /QuickEditLoadingTest

alexpott’s picture

StatusFileSize
new3.31 KB
new23.85 KB

Let's repeat all the tests to tease out random fails.

alexpott’s picture

StatusFileSize
new903 bytes
new23.89 KB

I can reproduce the postgres fails locally and the patch attached seems to fix them.

alexpott’s picture

StatusFileSize
new1.16 KB
new25.05 KB

Interesting new fails not on postgres... let's try to see what is going on.

alexpott’s picture

StatusFileSize
new822 bytes
new25.05 KB

Here's one more random fail fixed. Postgres sometimes is just a bit slow to load. It fails locally for me everytime without this.

I still can't explain all the fails in non-postgres environments in #29

alexpott’s picture

StatusFileSize
new3.14 KB
new28.73 KB

Let's see...

Status: Needs review » Needs work

The last submitted patch, 32: 3174928-32.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.57 KB
alexpott’s picture

StatusFileSize
new29.93 KB
alexpott’s picture

StatusFileSize
new2.4 KB
new31.82 KB

So #35 is way way more stable (less random fails) then anything previously but there's still at least one random fail in \Drupal\Tests\media_library\FunctionalJavascript\WidgetUploadTest::testWidgetUpload - see https://www.drupal.org/pift-ci-job/1847459 - the html output makes it look like the browser didn't register the click on 'media-3-remove-button' - all I can suspect is that the callback failed for some reason and we're not getting the JS error. So I've added some handling to try to extract JS errors based on https://github.com/minkphp/MinkSelenium2Driver/issues/189

Status: Needs review » Needs work

The last submitted patch, 36: 3174928-36.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1.36 KB
new32.04 KB

Status: Needs review » Needs work

The last submitted patch, 38: 3174928-38.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new2.01 KB
new32.47 KB

So it seems some of tests get JS errors and they are expected... so we can't always test there a no errors but this does prove that a JS error while AJAXing doesn't automatically cause a fail and so might the source of the remaining random fails...

alexpott’s picture

I've tried everything to find out why \Drupal\Tests\media_library\FunctionalJavascript\WidgetUploadTest::testWidgetUpload() fails sometimes on SQLite. The point of failure seems to have moved from what it outlined in #3066447: [random test failure] Random failures building media library form after uploading image (WidgetUploadTest) but it does seem related. It looks like the button presses sometimes don't not do anything. The two in question are $page->pressButton('media-1-remove-button'); on line 313 and $page->pressButton('media-3-remove-button'); on line 335. I think it is okay to leave this to be fixed in #3066447: [random test failure] Random failures building media library form after uploading image (WidgetUploadTest) - as the recent runs show this is only with SQLite and it very rare.

This issue started about making our tests work with the latest dev version of behat/mink-selenium2-driver but as that changed timeouts it quickly became about the stability of our JS tests. Therefore I'm going to split the scope of this issue and make it solely about JS test stability. I'll open a new issue about JS test conditions and removing the semi-colon.

alexpott’s picture

StatusFileSize
new1.64 KB

Here's a patch to do repeat JS testing on HEAD

alexpott’s picture

Here's the fixes from #40 plus repeat testing.

andypost’s picture

@alexpott maybe the issue is because of big pipe is involved, or because this forms using JS to submit data instead of form (I faced it when using settings tray)

alexpott’s picture

Title: Upcoming changes to behat/mink-selenium2-driver break Drupal's javascript testing » Improve the stability of core JS testing
Issue summary: View changes

Fixed the issue summary. Opened #3176361: Remove semi-colon from javascript test conditions for the JS conditions.

alexpott’s picture

@andypost what's odd is that the fail is DB specific. I suspect that the fail is due to the concurrency and SQLite. Drupal's use of SQLite does not handle concurrency that well.

alexpott’s picture

Here's the final patch that I think we should consider committing. It:

  • doesn't make any changes to run-time code
  • waits more appropriately for things
  • is more stable on dev-master of behat/mink-selenium2-driver
  • saves the html output when there is any error giving more info to go on when debugging
alexpott’s picture

StatusFileSize
new17.73 KB

Forgot to upload the patch.

The last submitted patch, 43: 3174928-2-44-fixes-plus-repeat-js-testing.patch, failed testing. View results

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.

alexpott’s picture

Attaching to the PHP 8.0 meta. The package maintainer will hopefully make a release soon so we need this done.

alexpott’s picture

Title: Improve the stability of core JS testing » Improve the stability of core JS testing and prepare for update of MinkSelenium2Driver
alexpott’s picture

Priority: Normal » Critical

Making critical as this will block updating because JS testing will become completely unstable.

lendude’s picture

#3061852: [META] Deprecate assertWaitOnAjaxRequest() and make the JsWebAssert::waitFor*() methods behave like real assertions seems very relevant for this. This is bound to wreak havoc in contrib testing too and currently we have no way to communicate that people should really stop using assertWaitForAjaxRequest.

alexpott’s picture

@Lendude I agree that #3061852: [META] Deprecate assertWaitOnAjaxRequest() and make the JsWebAssert::waitFor*() methods behave like real assertions is desirable but I don't think that this blocks us doing this issue to prep for updating and also contrib can lower the dependency and not support PHP8 until they've fixed their tests. We won't change the constraint.

alexpott’s picture

Also this issue does not wreck havoc itself. This issue will make contrib testing more stable due to improvements in the general test code. It's the update of the driver that might... however I think the general improvements will mitigate that.

andypost’s picture

I think we should commit it as it's not disruptive and the meta is great follow-up

Queued for sqlite/pgsql, locally affected tests running fine in-parallel on sqlite

lendude’s picture

@alexpott yeah sorry, my 'this' was meant for the change in MinkSelenium2Driver, not this issue

andypost’s picture

Status: Needs review » Reviewed & tested by the community

As I see pgsql is broken but not by this patch, so rtbc

catch’s picture

I'm not seeing the postgres fails on the branch: https://www.drupal.org/pift-ci-job/1866474 they can't be due to this issue since it's a kernel test that's failing but has anyone seen it elsewhere?

alexpott’s picture

@catch - yep it is #3118591: Datetime-related test failures on PostgreSQL 12 - it is only postgres 12. We test with 10 by default.

  • catch committed 9a28c1a on 9.2.x
    Issue #3174928 by alexpott, andypost: Improve the stability of core JS...

  • catch committed cff7a5b on 9.1.x
    Issue #3174928 by alexpott, andypost: Improve the stability of core JS...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

This looks good, will be great if we can get more consistent test runs overall out of it.

Committed cff7a5b and pushed to 9.2.x/9.1.x Thanks!

Status: Fixed » Closed (fixed)

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