Problem/Motivation

run-tests.sh spawns subprocesses of itself, each one then running a single PHPUnit test class via PHPUnit, which itself spawns suprocesses for each test to be run in isolation. Maybe we can skip one level and let the main run-tests.sh process directly spawn PHPUnit subprocesses.

Done:

Proposed resolution

  • Make the 'main' run-tests.sh directly spin PHPUnit CLI subprocesses.
  • Adjust PhpUnitTestRunner in order to allow it to run the spawned subprocesses asynchronously, so to support run-tests.sh concurrency.

All @internal code refactoring.

Notes on related issues

This issue is blocking #3536964: run-tests.sh - segregate command line parsing and use Symfony Console classes, which itself is blocking #3549601: Allow --directory and @group to work together in run-tests.sh which is an important feature for contrib testing, because @group often fails during Test Discovery for errors introduced in the changes at core 11.2.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3515347

Command icon 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

mondrake created an issue. See original summary.

mondrake’s picture

Title: Reduce run-tests.sh complexity in spawning subprocesses » [PP-4] Reduce run-tests.sh complexity in spawning subprocesses
Issue summary: View changes
Status: Active » Postponed
mondrake’s picture

Title: [PP-4] Reduce run-tests.sh complexity in spawning subprocesses » [PP-3] Reduce run-tests.sh complexity in spawning subprocesses
Issue summary: View changes
mondrake’s picture

Issue tags: +PHPUnit 11
mondrake’s picture

Title: [PP-3] Reduce run-tests.sh complexity in spawning subprocesses » [PP-2] Reduce run-tests.sh complexity in spawning subprocesses
Issue summary: View changes
mondrake’s picture

Title: [PP-2] Reduce run-tests.sh complexity in spawning subprocesses » [PP-1] Reduce run-tests.sh complexity in spawning subprocesses
Issue summary: View changes
mondrake’s picture

Title: [PP-1] Reduce run-tests.sh complexity in spawning subprocesses » Reduce run-tests.sh complexity in spawning subprocesses
Assigned: Unassigned » mondrake
Issue summary: View changes
Status: Postponed » Needs work

All blockers are in. Will be working on this one.

mondrake’s picture

Status: Needs work » Postponed
mondrake’s picture

Issue summary: View changes
Status: Postponed » Needs review
mondrake’s picture

Assigned: mondrake » Unassigned
smustgrave’s picture

Appears to have merge conflicts

If you are another contributor eager to jump in, please allow the previous poster(s) at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

mondrake’s picture

Status: Needs review » Postponed
mondrake’s picture

Status: Postponed » Needs review

Unblocked, rebased.

smustgrave’s picture

Recommended way for testing?

mondrake’s picture

#16 this is refactoring internal code, and no outside effects are expected. The only suggestion I would have is to compare test result logs from run-tests.sh, in core and contrib, before and after the change. They should be the same.

smustgrave’s picture

left a comment on the MR but leaving in review for additional eyes,

mondrake’s picture

Assigned: Unassigned » mondrake
Status: Needs review » Needs work

good catch. on that

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review

Adjusted the docblocks.

mondrake’s picture

Since run-tests.sh is no longer spawning subprocesses of run-tests.sh itself, we no longer need to persist the test result SQLite database on disk to allow parent-child processing. So, we can try using a :memory: SQLite database within the main run-tests.sh process.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Needs review

rebased

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Needs review

rebased

jonathan1055 made their first commit to this issue’s fork.

jonathan1055’s picture

Issue summary: View changes

96 commits behind, tried to rebase, but needed a merge. It was all clean, no conflicts.

Updated IS with notes on the related issues.

mondrake’s picture

Issue tags: +run-tests.sh
smustgrave’s picture

Status: Needs review » Needs work

Appeared to break phpstan?

mondrake’s picture

Status: Needs work » Needs review

#31 strange... fixed now.

longwave’s picture

Can we just default to --sqlite :memory: now, but keep the switch in case anyone wants to inspect the database later?

mondrake’s picture

Assigned: Unassigned » mondrake
Status: Needs review » Needs work

Sure, on that.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review

done #34

mondrake’s picture

Assigned: Unassigned » mondrake
Status: Needs review » Needs work

Needs some tuning.

mondrake’s picture

We cannot do #33, because undefined --sqlite currently means "use the installed database". So latest commits fail Kernel tests because they try inserting into the SUT db and not on the test runner db.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Needs work

needs reroll

mondrake’s picture

Status: Needs work » Needs review

solved merge conflicts

smustgrave’s picture

Not sure how to test this one :( but the pipeline is all green, let me see if I can get someone.

mondrake’s picture

see #17 for testing

smustgrave’s picture

Sorry which logs do you mean? And not sure how to test contrib

mondrake’s picture

For core, go to the MR, select Pipelines, then the first on the list, then pick one of the jobs. For instance, pick the DEFAULT child pipeline, then the first Kernel test job. This sequnce leads to https://git.drupalcode.org/issue/drupal-3515347/-/jobs/7716054.

This is the ‘job log’. You compare that with the one resulting from the same sequence in the HEAD branch, for instance the one running Daily.

For contrib, you need to run on a local environment tests for a module via run-tests.sh before and after applying the MR. See https://www.drupal.org/docs/develop/automated-testing/phpunit-in-drupal/...

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mondrake’s picture

Status: Needs work » Needs review

updated fork

jonathan1055’s picture

For Contrib testing, I will try to use this MR as a patch in a Gitlab Templates CI pipeline. This does not replace the suggestion in #44, it's an extra. I am interested in getting this done, to unblock #3549601: Allow --directory and @group to work together in run-tests.sh

mondrake’s picture

Version: 11.x-dev » main
jonathan1055’s picture

Following up my comment in #47 I have now tested this MR in a Contrib pipeline, which has quite a few phpunit tests, split over 6 parallel matrix streams. The patching worked on run-tests.sh ok (ignore the fact that it failed on a few of the test files modifed here).

https://git.drupalcode.org/issue/scheduler-3356800/-/jobs/8141884#L201

The tests ran, exactly as before. The log output is identical except for some formatting around

Drupal test run
--------------------------------------------------------------
Drupal Version.......: 11.3.2

The new long line shows that it is running the modified run-tests.sh, because that is one of the changes in the patch. It is nice to see visible proof, to confirm that.

I know that running time was not the primary aim of this MR, but on a sample of one pipeline before and one after, five of the six parallel test groups were faster in the newer version, ranging from 5% to 14% quicker over tests taking 2 mins to 11 mins. One test was slower but this was 30s to 35s so not actually significant. This is only a sample of one, so not statistically definitive, but it is good. At least it seems that the modified script is producing the same outcomes as before

mondrake’s picture

Thanks for #49.

Since each test class requires one less subprocess to be spawned, and a subprocess initiation can take up to 0.2 seconds (roughly), yes there can be some performance improvements. Especially in runs of many test classes whose individual execution time is small (typically, unit tests). Kernel and Functional test have quite some overhead of its own so it’s less visible there.

jonathan1055’s picture

StatusFileSize
new465 bytes

Just in case anyone else would like to try the same as I did on their contrib project, here is the phpunit: before_script customisation I used.

mondrake’s picture

Issue tags: +Test suite performance
dcam’s picture

Status: Needs review » Needs work

I did my best to study the code since I've never looked at it before. I found a few things and commented on them in the MR. I'm mostly setting the status to Needs Work because I think I found the potential for a fatal error with that $testClass property.

mondrake’s picture

Status: Needs work » Needs review

Thanks for diving into this code @dcam. Addressed your comments.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

I diffed most of the tests from this MR versus another simple MR that I worked on today. There was effectively no difference between them, which I think is the point. For the most part, all the tests ran (or at least were reported) in the same groups in the exact same order. The Unit test (Core) summary sections showed the classes in different orders, but the details results sections were the ordered the same. I don't know if that's typical or not.

Anyway, it looks to me like all the tests are still running exactly as they should be after the change. I'm going to RTBC it.

mondrake’s picture

Well the order in the summary section depends on the efficiency of the parallelization (as reported in #49), and on the speed of the runner. Especially with unit tests that run many short lasting classes in parallel the resulting order may vary wildly. As long as the total count matches, it’s OK imho. Did not know the detailed report is comparable, good thing.

jonathan1055’s picture

In the MR you made the comment that PHPCS is not being run on run-tests.sh and I think the reason is that the core phpcs.xml.dist file does not include sh in the list of extensions, probably because in general .sh files are bash scripts not php. But it seems there was an attempt to include specific .sh files in the check. I don't know if this ever worked, but it certainly does nothing now, at least locally for me, because the list in "extensions" overrides any exceptions here.

Maybe it is worth opening a separate issue for this? If you agree I will do that. The check can be done in a second separate call to phpcs with a custom list of extensions, if there is no appetite to add 'sh' into the extensions list in the file.

mondrake’s picture

#57 makes a lot of sense, and yeah I think that belongs to a separate issue, thanks

jonathan1055’s picture

I have opened #3568959: PHPCS ignores the attempt to check run-tests.sh
Also adding the meta issue as parent here.

catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Looks really good - net reduction in code, moves more logic out of run-tests.sh, unblocks more things later too.

Committed/pushed to main and 11.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed 9644cf01 on 11.x
    task: #3515347 Reduce run-tests.sh complexity in spawning subprocesses...

  • catch committed ab5a470b on main
    task: #3515347 Reduce run-tests.sh complexity in spawning subprocesses...
jonathan1055’s picture

Status: Fixed » Closed (fixed)

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