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
| Comment | File | Size | Author |
|---|---|---|---|
| #48 | 3174928-2-47.patch | 17.73 KB | alexpott |
Comments
Comment #2
alexpottComment #4
alexpottSome more fixes.
Comment #6
alexpottWow 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.
Comment #7
alexpott#6 is gonna fail lets bump the wait to 1second.
Comment #8
alexpottFor more info on the setTimeouts thing see https://developer.mozilla.org/en-US/docs/Web/WebDriver/Commands/SetTimeouts
Comment #10
alexpottBump the timeout to 2secs (note the wait timeout is 10secs) and fix a few more colons.
Comment #12
andypostLooks this changes needs CR
Comment #14
alexpott@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
Comment #15
alexpottComment #17
alexpottComment #18
alexpottSo let's see if the implicit wait is actually doing anything...
Comment #20
alexpottComment #23
andypostLooks pgsql needs more then 200ms timeouts to pass fragile quick edit test
Comment #24
alexpottMoving stuff around to see if we can make the quickedit test more reliable. Nearly all of our problems are caused by assertWaitOnAjaxRequest
Comment #25
alexpottComment #26
alexpottIgnore the Postgres 9.5 test in #25 D9 does not support that version of Postgres.
Comment #27
alexpottLet's get rid of all assertWaitOnAjax... in /QuickEditLoadingTest
Comment #28
alexpottLet's repeat all the tests to tease out random fails.
Comment #29
alexpottI can reproduce the postgres fails locally and the patch attached seems to fix them.
Comment #30
alexpottInteresting new fails not on postgres... let's try to see what is going on.
Comment #31
alexpottHere'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
Comment #32
alexpottLet's see...
Comment #34
alexpottComment #35
alexpottComment #36
alexpottSo #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/189Comment #38
alexpottComment #40
alexpottSo 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...
Comment #41
alexpottI'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.
Comment #42
alexpottHere's a patch to do repeat JS testing on HEAD
Comment #43
alexpottHere's the fixes from #40 plus repeat testing.
Comment #44
andypost@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)
Comment #45
alexpottFixed the issue summary. Opened #3176361: Remove semi-colon from javascript test conditions for the JS conditions.
Comment #46
alexpott@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.
Comment #47
alexpottHere's the final patch that I think we should consider committing. It:
Comment #48
alexpottForgot to upload the patch.
Comment #51
alexpottAttaching to the PHP 8.0 meta. The package maintainer will hopefully make a release soon so we need this done.
Comment #52
alexpottComment #53
alexpottMaking critical as this will block updating because JS testing will become completely unstable.
Comment #54
lendude#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.
Comment #55
alexpott@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.
Comment #56
alexpottAlso 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.
Comment #57
andypostI 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
Comment #58
lendude@alexpott yeah sorry, my 'this' was meant for the change in MinkSelenium2Driver, not this issue
Comment #59
andypostAs I see pgsql is broken but not by this patch, so rtbc
Comment #60
catchI'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?
Comment #61
alexpott@catch - yep it is #3118591: Datetime-related test failures on PostgreSQL 12 - it is only postgres 12. We test with 10 by default.
Comment #64
catchThis 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!