Improve concurrency: replace experimental package with core script

Created on 31 August 2023, over 1 year ago
Updated 19 September 2023, over 1 year ago

Problem/Motivation

We are currently using "phpunit" or "paratests" binaries to run tests. "paratest" was intruduced as a way to speed up the total running time of a pipeline.

Several improvements were made to the GitLab CI runners, among those loading folders and database in ramdisk, speeding up the execution of tasks.

In addition to that, the Drupal core gitlabci templates are being worked in https://www.drupal.org/project/gitlab_ci_testbed_for_drupal_core β†’ and when working on this issue #3374070: Experiment with concurrency package β†’ it was proved that the scripts included in core to run tests are more efficient and leverage the concurrency capabilities of apache.

So that means that we can improve the way to run jobs concurrently. In addition to the performance gain, we get the same output and artifacts that we normally get when running DrupalCI for contrib modules.

See the contrib gains running parallel tasks with:
* Paratests (4 minutes 24 seconds): https://git.drupalcode.org/project/api/-/jobs/72378
* Drupal core "run-tests.sh" (2 minutes 28 seconds): https://git.drupalcode.org/project/api/-/jobs/72384

Steps to reproduce

Set _PHPUNIT_CONCURRENT=1 in your variables. Your tests will be run in parallel but you will lose some features, like the browser_output folders.

Proposed resolution

Replace the experimental "paratest" for the well-tested script included in core to run the tests.

Consider setting _PHPUNIT_CONCURRENT to 1 by default. It's currently set to 0 as "paratest" was experimental, but we are removing it now in favor of a well-tested and used way of running the tests concurrently.

See the same job run:
* Non-concurrent (phpunit): https://git.drupalcode.org/project/api/-/jobs/72414
* Concurrently (run-tests.sh): https://git.drupalcode.org/project/api/-/jobs/72427

Remaining tasks

MR

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Fixed

Component

gitlab-ci

Created by

πŸ‡ͺπŸ‡ΈSpain fjgarlin

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

Comments & Activities

  • Issue created by @fjgarlin
  • @fjgarlin opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    This is ready for review.

    I'm using it already on a contrib module overwriting the gitlab-ci template. See here: https://git.drupalcode.org/project/api/-/blob/2.x/.gitlab-ci.yml#L50

    The MR with the changes is here: https://git.drupalcode.org/project/gitlab_templates/-/merge_requests/41/...

  • First commit to issue fork.
  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States hestenet Portland, OR πŸ‡ΊπŸ‡Έ

    Merged! Thanks for the work here.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States moshe weitzman Boston, MA

    When CONCURRENCY is used, are the tests running with sqlite regardless of the DB that the user specified. Or is just a results table thats using sqlite? If its the former, we should error out if the specified DB was mysql or postgres IMO.

    Also, we are now not honoring _PHPUNIT_EXTRA, and making unavailable all the CLI options that are used with it (--fail-on-warning, --filter, --exclude-group, ...).

    IMO we should start with core overriding in run-tests.sh. If we can make that generally useful for contrib projects, it belongs in gitlab_templates. My .02

  • @fjgarlin opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    I added another minor MR with really small changes, mostly text to document the variables and also allow _PHPUNIT_EXTRA even in concurrent mode. The MR is here: https://git.drupalcode.org/project/gitlab_templates/-/merge_requests/42/...

    You can ignore the hardcoded "sqlite" argument as that is specific to "run-tests.sh" and is related to the "keep-results" argument. The database for the tests is respected, whether it's mysql, pssql or sqlite.

    _PHPUNIT_EXTRA will continue working with default "phpunit" options if _PHPUNIT_CONCURRENT is set to 0 (default value), so there is no change there at all.
    If _PHPUNIT_CONCURRENT is set to 1, then the value for _PHPUNIT_EXTRA will be options for the "run-tests.sh" script.

    I documented the above in the MR above.

  • Status changed to Fixed over 1 year ago
  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    @moshe-weitzman - I'm not sure if you have more feedback here. The goal of the issue was achieved and everything keeps on being under the "experimental" feature.

    Are there any specifics that you want to address or discuss? I will mark it as fixed but feel free to re-open, ping, create a follow-up with any thoughts.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    In #9 @moshe-weitzman wrote

    Also, we are now not honoring _PHPUNIT_EXTRA, and making unavailable all the CLI options that are used with it (--fail-on-warning, --filter, --exclude-group, ...).

    In #11 @fjgarlin replied

    _PHPUNIT_EXTRA will continue working with default "phpunit" options if _PHPUNIT_CONCURRENT is set to 0 (default value), so there is no change there at all.
    If _PHPUNIT_CONCURRENT is set to 1, then the value for _PHPUNIT_EXTRA will be options for the "run-tests.sh" script.
    I documented the above in the MR

    I've hit this problem, I was using --group to divide the phpunit test into parallel streams, and it was working fine but now fails with

    PHP Warning:  Trying to access array offset on value of type null in /builds/project/scheduler/web/core/scripts/run-tests.sh on line 1270
    ERROR: Unknown argument '--group'.
    

    To get --group to work and split the job into parallel streams it looks like I will have to set the value of _PHPUNIT_EXTRA varying, depending on the value of _PHPUNIT_CONCURRENT

  • πŸ‡ͺπŸ‡ΈSpain fjgarlin

    Yes, that is correct. Apologies.

    We found out that leveraging apache and the run-tests.sh script from core we could get better results than using the experimental package "paratest" (which didn't support all options).

    We are working with core maintainers to potentially increase even more the concurrency options when this is used with GitlabCI.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Thanks for the feedback.

    I have found a difficulty with using the updated template implementation of run-tests.sh, so have raised #3388185: Tests cannot be filtered by @group when running with phpunit_concurrent=1 β†’ to work on it.

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

Production build 0.71.5 2024