GitLab CI: PHPUnit, FunctionalJavascript tests failing with 'RuntimeException: Unable to complete AJAX request.' on D10.2

Created on 7 January 2024, 12 months ago
Updated 28 January 2024, 11 months ago

Problem/Motivation

GitLab CI now passes, except PHPUnit produces the following error:

There was 1 error:
1) Drupal\Tests\structure_sync\FunctionalJavascript\StructureSyncMenuLinksTest::testMenuLinksExportImportUsingAdmin
RuntimeException: Unable to complete AJAX request.
/builds/issue/structure_sync-2980893/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:53
/builds/issue/structure_sync-2980893/tests/src/FunctionalJavascript/StructureSyncMenuLinksTest.php:90
/builds/issue/structure_sync-2980893/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
ERRORS!

See: https://git.drupalcode.org/issue/structure_sync-2980893/-/jobs/585909

Steps to reproduce

Run GitLab pipeline with variable _TARGET_CORE = $CORE_SECURITY_PREVIOUS_MINOR
or _TARGET_CORE = $CORE_SUPPORTED to avoid composer failing due to drush version, see 🐛 Update drush conflict to "<12.4.3" RTBC .

Proposed resolution

Based on: #3316274-118: Stabilize FunctionalJavascript testing AJAX: add ::assertExpectedAjaxRequest()

Just FYI for anyone else that finds this issue because their assertWaitOnAjaxRequest() calls started failing, you need to now enable js_testing_ajax_request_test for any JS test that uses this function.

js_testing_ajax_request_test provides test JS code that set window.drupalActiveXhrCount and window.drupalCumulativeXhrCount. Those variables are required to have a successful assertWaitOnAjaxRequest call.

Add Core test module js_testing_ajax_request_test to the modules to be enabled for automated Functional Javascript Test case Drupal\Tests\structure_sync\FunctionalJavascript\StructureSyncMenuLinksTest::testMenuLinksExportImportUsingAdmin in Test class StructureSyncMenuLinksTest.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇫🇷France dydave

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dydave
  • 🇫🇷France dydave

    I've made some tests directly on GitlabCI issue fork's pipeline at:
    https://git.drupalcode.org/issue/structure_sync-3412960/-/pipelines

    and was able to identify a first issue with the version constraint on Drush in module's composer.json to be compatible with D10.2, which now requires drush/drush:^12, see:
    https://git.drupalcode.org/issue/structure_sync-3412960/-/commit/86bdbd5...
    With the following changes:

    diff --git a/composer.json b/composer.json
    index 3d61973e7816d3d9ca8f657556e684714c128092..be271edffe0fe39e95ac2fba4fdedeac25367f90 100644
    --- a/composer.json
    +++ b/composer.json
    @@ -8,12 +8,12 @@
             "php": ">=7.1"
         },
         "require-dev": {
    -        "drush/drush": "^9 || ^10 || ^11"
    +        "drush/drush": "^9 || ^10 || ^11 || ^12"
         },
         "extra": {
             "drush": {
                 "services": {
    -                "drush.services.yml": "^9 || ^10 || ^11"
    +                "drush.services.yml": "^9 || ^10 || ^11 || ^12"
                 }
             }
         }
    

    which now allows testing with 10.2.x: _TARGET_CORE = $CORE_SUPPORTED.
    nbsp;

    and we're now seeing all calls to assertWaitOnAjaxRequest() fail, as mentioned in #3316274-118: Stabilize FunctionalJavascript testing AJAX: add ::assertExpectedAjaxRequest() :(

    There were 3 errors:
    1) Drupal\Tests\structure_sync\FunctionalJavascript\StructureSyncBlocksTest::testBlocksExportImportUsingAdmin
    RuntimeException: Unable to complete AJAX request.
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:117
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:38
    /builds/issue/structure_sync-3412960/tests/src/FunctionalJavascript/StructureSyncBlocksTest.php:135
    /builds/issue/structure_sync-3412960/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    2) Drupal\Tests\structure_sync\FunctionalJavascript\StructureSyncMenuLinksTest::testMenuLinksExportImportUsingAdmin
    RuntimeException: Unable to complete AJAX request.
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:117
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:38
    /builds/issue/structure_sync-3412960/tests/src/FunctionalJavascript/StructureSyncMenuLinksTest.php:92
    /builds/issue/structure_sync-3412960/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    3) Drupal\Tests\structure_sync\FunctionalJavascript\StructureSyncTaxonomiesTest::testTaxonomiesExportImportUsingAdmin
    RuntimeException: Unable to complete AJAX request.
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:117
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:38
    /builds/issue/structure_sync-3412960/tests/src/FunctionalJavascript/StructureSyncTaxonomiesTest.php:86
    /builds/issue/structure_sync-3412960/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    ERRORS!
    

    I have tried including specifically core Test module js_testing_ajax_request_test, but it didn't seem to make any difference, see for example:

    diff --git a/tests/src/FunctionalJavascript/StructureSyncBlocksTest.php b/tests/src/FunctionalJavascript/StructureSyncBlocksTest.php
    index b537d11838d96fc48be8e77af7cc1d6a411dc50a..fa4a313864ff75d6965d3c65378d91288082c409 100644
    --- a/tests/src/FunctionalJavascript/StructureSyncBlocksTest.php
    +++ b/tests/src/FunctionalJavascript/StructureSyncBlocksTest.php
    @@ -23,6 +23,8 @@ class StructureSyncBlocksTest extends WebDriverTestBase {
       protected static $modules = [
         'structure_sync',
         'block_content',
    +    // Prevent tests from failing due to 'RuntimeException' with AJAX request.
    +    'js_testing_ajax_request_test',
       ];
    

    We need to probably look at other contrib modules which use assertWaitOnAjaxRequest() in their tests and see if they are able to go through or fail as well...
    To be further investigated and tested.

    Any feedback, comments, suggestions, advice or recommendations would be greatly appreciated!
    Thanks in advance!

  • 🇫🇷France louis-cuny

    Thank you for your contribution

    Isn't this issue 📌 Stabilize FunctionalJavascript testing AJAX: add ::assertExpectedAjaxRequest() Fixed fixing this error in drupal 10.2+ ?

  • 🇫🇷France dydave

    Hi Louis (@louis-cuny),

    Thanks a lot for your prompt reply and follow-up on this, it's greatly appreciated.

    Thankfully, I'm reproducing this locally on 10.2.x: same exact errors, so at least we know it's not something related with the GitLab CI infrastructure, but with the Test files of the module themselves, in particular the call to assertWaitOnAjaxRequest.
    I'll do a bit more digging and debugging a bit later, when I get some more time.

    Any feedback, suggestions or ideas on how to fix these errors would be greatly appreciated.
    Thanks in advance !

  • Status changed to Needs review 12 months ago
  • 🇫🇷France dydave

    Quick follow-up on this issue:

    I was able to do a bit more debugging of the tests locally and ended up replacing the calls to assertWaitOnAjaxRequest with waitForElementVisible.
    In other words: Wait until the batch operation completes and gets us back to the admin page with the buttons.

    But after the second commit, fixing the tests calls in all files, I noticed the PHPUnit Test for Menu items (StructureSyncMenuLinksTest) was still failing with the following error:

    Time: 00:50.645, Memory: 6.00 MB
    There was 1 error:
    1) Drupal\Tests\structure_sync\FunctionalJavascript\StructureSyncMenuLinksTest::testMenuLinksExportImportUsingAdmin
    WebDriver\Exception\NoSuchElement: Element not found with xpath, descendant-or-self::*[@id = 'edit-import-menus-full']
    no such element: Unable to locate element: {"method":"xpath","selector":"descendant-or-self::*[@id = 'edit-import-menus-full']"}
      (Session info: headless chrome=106.0.5249.103)
      (Driver info: chromedriver=106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249@{#569}),platform=Linux 5.4.241-150.347.amzn2.x86_64 x86_64)
    /builds/issue/structure_sync-3412960/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:198
    /builds/issue/structure_sync-3412960/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:85
    /builds/issue/structure_sync-3412960/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:962
    /builds/issue/structure_sync-3412960/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:759
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php:122
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php:202
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php:133
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/Tests/UiHelperTrait.php:384
    /builds/issue/structure_sync-3412960/tests/src/FunctionalJavascript/StructureSyncMenuLinksTest.php:110
    /builds/issue/structure_sync-3412960/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    Caused by
    WebDriver\Exception\NoSuchElement: no such element: Unable to locate element: {"method":"xpath","selector":"descendant-or-self::*[@id = 'edit-import-menus-full']"}
      (Session info: headless chrome=106.0.5249.103)
      (Driver info: chromedriver=106.0.5249.61 (511755355844955cd3e264779baf0dd38212a4d0-refs/branch-heads/5249@{#569}),platform=Linux 5.4.241-150.347.amzn2.x86_64 x86_64)
    /builds/issue/structure_sync-3412960/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:198
    /builds/issue/structure_sync-3412960/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:169
    /builds/issue/structure_sync-3412960/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:72
    /builds/issue/structure_sync-3412960/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:962
    /builds/issue/structure_sync-3412960/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:759
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php:122
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php:202
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/FunctionalJavascriptTests/DrupalSelenium2Driver.php:133
    /builds/issue/structure_sync-3412960/web/core/tests/Drupal/Tests/UiHelperTrait.php:384
    /builds/issue/structure_sync-3412960/tests/src/FunctionalJavascript/StructureSyncMenuLinksTest.php:110
    /builds/issue/structure_sync-3412960/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    ERRORS!
    Tests: 6, Assertions: 79, Errors: 1.
    

     
    So I started testing the module manually as well, through the form, and noticed sometimes the batch would never finish (although all config items would have been processed), because of a bug/regression introduced in issue 🐛 Import breaks when no menu's have been exported (patch available) Fixed and its corresponding commit.
    So the previous changes were reverted and an alternate implementation was suggested, in which the command drush import:menus does't crash and prints out a log message instead:

    $ drush import:menus --choice safe
    Importing menu links...
    Using "Safe" import style
     [notice] Menu links import started
     [notice] Using "safe" style for menu links import
     [notice] No menu exported: Nothing to import.
    Menus need to be exported first before they can be imported.
     [notice] No menu exported: Nothing to import.
    Menus need to be exported first before they can be imported.
    

    After fixing this regression, the Tests on D10.2 seem to be back to green ✅ \o/:
    https://git.drupalcode.org/issue/structure_sync-3412960/-/pipelines/76588

    Once these changes are merged, it should be much safer to review other patches and merge requests in the issue queue, for the 2.x branch. Therefore, these changes should probably be reviewed in priority, so other patches could be properly tested.
     

    We would greatly appreciate if you could please try testing and reviewing the changes from the merge request and give us your feedback.

    Feel free to let us know if you have any questions, concerns, suggestions or comments on any of the changes from MR!30, this ticket or module's Automated Tests in general, we would surely be glad to help.
    Thanks in advance for your feedback, testing and reviews.

  • Status changed to Needs work 12 months ago
  • 🇫🇷France louis-cuny

    Thank you for your contribution

    Almost good about this one, I reviewed the changes for now
    Will test it later

  • Status changed to Needs review 12 months ago
  • 🇫🇷France dydave

    Thanks a lot Louis (@louis-cuny) for catching these lines and your comments in the merge request.

    I've made the requested changes and updated the !MR30, which seems to still pass ✅:
    https://git.drupalcode.org/issue/structure_sync-3412960/-/pipelines/77064

    Once again, we would greatly appreciate your feedback and comments on this update merge request.
    Feel free to let us know if you spot anything else, or have more comments, we would surely be glad to help.
    Thanks in advance.

  • Status changed to Fixed 12 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024