Problem/Motivation
Tests run through CI frequently fail on FunctionalJavascript tests.
This may happen through either GitlabCI or DrupalCI. Rerunning the test usually results in success.
Example failure:
There were 2 errors:
1) Drupal\Tests\project_browser\FunctionalJavascript\ProjectBrowserInstallerUiTest::testCanBreakStageWithMissingProjectBrowserLock
Error: Call to a member function getText() on null
/var/www/html/modules/contrib/project_browser/tests/src/FunctionalJavascript/ProjectBrowserInstallerUiTest.php:167
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
2) Drupal\Tests\project_browser\FunctionalJavascript\ProjectBrowserInstallerUiTest::testCanBreakLock
Error: Call to a member function getText() on null
/var/www/html/modules/contrib/project_browser/tests/src/FunctionalJavascript/ProjectBrowserInstallerUiTest.php:200
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
--
There was 1 failure:
1) Drupal\Tests\project_browser\FunctionalJavascript\ProjectBrowserInstallerUiTest::testModuleAddAndInstall
Failed asserting that a NULL is not empty.
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/var/www/html/modules/contrib/project_browser/tests/src/FunctionalJavascript/ProjectBrowserInstallerUiTest.php:72
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:728Steps to reproduce
Run tests in DrupalCI or GitlabCI. May fail.
Proposed resolution
The failure occurs in an assert immediately after $assert_session->waitForElementVisible. I'm not an expert on FunctionalJavascript tests, but I'm wondering if it's a timing issue, and the test is trying the assertion before the element is fully loaded. Could the more complex Svelte scripts be more taxing on the browser engine causing the wait to complete before the element is fully ready?
Not sure if there is any way to add an extra delay to give it a chance to catch up?
Issue fork project_browser-3420552
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
lostcarpark commentedThis change seems to be working quite well in GitlabCI. Since introducing even a very small delay, I have not seen any failures of FunctionalJS tests in GitlabCI.
However, in DrupalCI, even waiting a half second after the
waitFor()call, the tests almost always fail.Comment #4
lostcarpark commentedBecause I haven't been able to get FunctionalJavascript tests working reliably in DrupalCI, I suggest turning them off. They are running in GitlabCI, so running them in both environments is redundant.
This change does the following:
WebDriverTestBasewithProjectBrowserWebDriverTestBase, a subclass which adds a 1ms delay afterwaitForcalls, and seems to prevent the FunctionalJavascript tests failing in GitlabCI.testgroups: '', effectively telling DrupalCI to run no FunctionalJS testgroups.I'm not sure 1 is totally necessary, but FunctionalJS tests seemed to be failing quite a lot in both systems, and adding the delay seems to make them pass reliably in GitlabCI.
Also not sure if I've put the new classes in the correct place. I tried putting them in the FunctionalJavascript folder, but
ProjectBrowserWebAssertcan't be an abstract class.Comment #5
lostcarpark commentedComment #6
lostcarpark commentedComment #7
chrisfromredfinHad a conversation with testing expert extraordinaire Matt Glaman on Mar 6. We discussed several things to try:
Comment #10
lostcarpark commentedI have disabled the parallel running in
.gitlab-ci.yml. I have run 3 times in a row without any failures. Probably should try a few more to be sure, but that seems good enough to move to Needs Review.Should we leave the parallel section commented for now, on the assumption that we intend to restore it later, or delete it?
Comment #12
chrisfromredfinIs it possible to leave the other three types running in parallel?
Comment #13
fjgarlin commentedCore has a fair share of intermittent and random failures too, see #2829040: [meta] Known intermittent, random, and environment-specific test failures.
Turning the parallel off is a good measure, another one could be to tweak the resources given to the jobs (see how core tweaks the KUBERNETES_CPU_REQUEST per job). More demanding jobs might need a higher value than less demanding. The default for contrib is relatively low, because that's enough for most modules, but it's totally ok to tweak as needed.
Also, having said all the above, simplifying the current GitLab CI integration (as proposed in the MR https://git.drupalcode.org/project/project_browser/-/merge_requests/444/...) is not a bad idea. This module will eventually be in core, so the less customizations we have for GitLab CI, the easier to move to core.
Comment #14
lostcarpark commentedBy default, tests are allocated 2 CPU cores. As the Project Browser tests are quite intensive, this is giving inadequate resources.
Increasing the value of
KUBERNETES_CPU_REQUESTto 16 will hopefully give the tests sufficient resources.However, while I had several successful test runs, I did have one failure of the FunctionalJavascript tests, even with this change.
I'm hopeful that this will improve reliability, but I think we also need to look at moving some of the tests to Nightwatch.
Comment #15
fjgarlin commentedMR looks good to me. RTBC.
Yeah, we're bound to have the occasional random failure. Even core can't get rid of them #2829040: [meta] Known intermittent, random, and environment-specific test failures, and I can assure you that a lot of hours of investigation have gone into those issues too. Clicking the occasional "re-test" should be ok, and hopefully, this change will make it more reliable and stable.
Comment #17
chrisfromredfinOK this is a good incremental improvement which unblocks some other folks & tickets, so we should do it.