Problem/Motivation

run-tests.sh has logic to split the list of tests to be executed to separate bins that can be run in parallel to leverage GitLabCI parallelization capabilities.

This logic is intertwined with the test discovery process and cannot be tested ATM.

Proposed resolution

  1. separate test allocation to bins into a TestWorkAllocator class, that takes as input the output of the test discovery
  2. extend the logic to sort slow vs normal tests also to test discovery methods that use '--class', '--file' and group selection
  3. add unit testing for the new class

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3538002

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

Issue summary: View changes
Status: Active » Needs review
smustgrave’s picture

Recommended way to test this one?

mondrake’s picture

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

Issue tags: -PHPUnit 12
mondrake’s picture

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

Title: run-tests.sh - separate test allocation to bins into a TestWorkAllocator class » run-tests.sh - separate test allocation to bins into a WorkAllocator class
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

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

dcam’s picture

Status: Needs review » Needs work

This was a rough one. I've looked at it a few times over the last several months and never actually made it all the way through a review. But I vowed to get it done today.

I found a couple of things to comment on in the MR and am setting the status to Needs Work.

The array indentation in the new test's data provider is inconsistent. That made it kind of hard to review, especially the case that was ~1400 lines long. I had to fix some of it locally in order to parse what I was seeing. I don't know if there's a way to automatically indent those arrays properly, but if there is then it would help.

I did my best to review the code moves and changes. Overall I think they look good. The test results look good. I rebased the MR and then compared the test results to those from the latest commit to Core from this morning. There were minor differences between them, so it wasn't comparing apples to apples. But I assumed from the beginning that would happen. For instance, in the Kernel tests the list of discovered classes was slightly off when I diffed them. And that resulted in tests getting allocated to different bins. This isn't a problem. The number of tests that were discovered each type was exactly the same. And the tests were assigned to the bins in round-robin fashion as designed. So I'm convinced that the test discovery and allocation is working properly.

mondrake’s picture

@dcam thanks for your effort. Yes working with this script is painful. Hopefully we're on a good path in moving this script tasks into dedicated unit testable subclasses. In this case, separating the allocation of test into separate parallel bins into this TestWorkAllocator class could potentially open up for a later alternative implementation like #3040694: Use previous PHPUnit JUnit results to pack tests in bins when parallelizing.

dcam’s picture

StatusFileSize
new112.53 KB

I can't provide a suggestion for fixing the array indentations. The file is too big. It makes the browser lag and there's too much too select. So I made a patch that should apply on top of the MR. It's attached. Please consider it and double-check my work. There were a lot of changes. I already caught one section that I missed on a review of it and had to recreate the patch.

mondrake’s picture

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

#15 that’s just data, that was dumped with a var_export call. We shouldn’t be worrying about reviewing it IMHO. Sorry it caused such trouble.

Maybe we can do something like core/tests/Drupal/Tests/Component/Utility/RandomTest.php - dump the data in JSON format in a separate fixture file, and remove it from code.

Will do.

mondrake’s picture

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

Done #16 - now I think the MR should be more readable.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Yes, thank you very much for coming up with this alternative option and enacting it. It's a lot easier to compare the outputs of the test cases and understand what's going on now.

My feedback has been addressed. This looks good to me.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some feedback/suggestions. There are a lot of comments that don't appear to add much.

mondrake’s picture

Status: Needs work » Needs review

@longwave I addressed some of your points - there are still 3 more that would mean a wider refactoring of the algorithm that I would suggest to defer to a follow-up. Here the main intention was to move code away from run-tests.sh to a class of its own; doing refactoring of the new class will be simpler.

mondrake’s picture

rebased

dcam’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed the recent commits. The changes look OK to me. @longwave's feedback was addressed.

For what it's worth, in code-move issues my preference is to limit changes to that code as much as possible. In my opinion it makes reviews easier. But I understand not everyone may share that sentiment.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » 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 » Reviewed & tested by the community

  • longwave committed 7410fa37 on main
    test: #3538002 run-tests.sh - separate test allocation to bins into a...
longwave’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 7410fa37545 to main. Thanks!

Doesn't apply cleanly to 11.x, but I'm assuming we're not going to backport this sort of thing now. Please reopen if that's not the case!

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.

mondrake’s picture

Status: Fixed » Patch (to be ported)
Related issues: +#3549601: Allow --directory and @group to work together in run-tests.sh

It may be good to backport to 11.4 since I think contrib is willing to get #3549601: Allow --directory and @group to work together in run-tests.sh there too - maybe @jonathan1055 has an opinion?

mondrake’s picture

Version: main » 11.x-dev

mondrake’s picture

Title: run-tests.sh - separate test allocation to bins into a WorkAllocator class » [backport] run-tests.sh - separate test allocation to bins into a WorkAllocator class
Status: Patch (to be ported) » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a fine backport.

quietone’s picture

Title: [backport] run-tests.sh - separate test allocation to bins into a WorkAllocator class » run-tests.sh - separate test allocation to bins into a WorkAllocator class

The special title docs states that "[backport]" is for "The issue is for porting a patch from another issue to a previous version of the project.". Since this is the same issue, I am removing that from the title.

catch’s picture

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

Discussed briefly with @longwave - going ahead with the backport here to make the backport of #3549601: Allow --directory and @group to work together in run-tests.sh easier.

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 7163ff65 on 11.4.x
    task: #3538002 run-tests.sh - separate test allocation to bins into a...

  • catch committed eff16e6e on 11.x
    task: #3538002 run-tests.sh - separate test allocation to bins into a...

catch’s picture

Status: Reviewed & tested by the community » Fixed

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.