Problem/Motivation
In drupalci.yml the value of testsgroups: can accept a comma-separated list of two (or more) test group names to match against the @group value in the test files. When using two values I discovered that some tests are not selected even though others with the same matching @group are selected. After more trial runs I found out that the order of specifying the two values makes a difference to the final list of tests that are selected. I also found out that removing a test from one of the groups allowed one of the non-found tests to be re-discovered and run. See the investigations on #3251399: Drupalci.yml filtering for testgroups: 'scheduler,scheduler_api' does not run all the required tests
Steps to reproduce
Run a test with two values for testgroups, for example in drupalci.yml have testgroups: 'group_a,group_b'.
Providing that you have at least one test in each @group the total number of tests that are run will be fewer than should be. Some with a matching @group are lost.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3251817-9.patch | 905 bytes | alexpott |
| #9 | 4-9-interdiff.txt | 905 bytes | alexpott |
| #4 | 3251817-4.run-tests-with-multiple-groups.patch | 492 bytes | jonathan1055 |
Comments
Comment #2
jonathan1055 commentedMy hunch was that there is a bug in how the selection of tests are collected and/or merged. I found out how to test this locally, by calling
php core/scripts/run-tests.sh scheduler,scheduler_apiin this example. Here is my output from run-tests.sh --listI have cut down the number of tests locally, to make this example easier to read. There are two tests in
@group scheduler(AdminSettings and BasicMedia) and 1 test in@group scheduler_api(Events). Each test class only has one @group, they are not in multiple groups. There is a third @group scheduler_rules_integration which we do not want to run, hence the reason for specifying the two groups in the drupalci.yml testgroups parameter.Comment #3
jonathan1055 commentedAdding debug to run-tests.sh function
simpletest_script_get_test_listwe see:After the second loop we have
Then the line
array_flip($test_list)causes one of the tests to get dropped, because there are two with value 0However, simply changing to use
array_keys($test_list)we keep all the testsComment #4
jonathan1055 commentedHere's a patch that makes the single line change. I've searched for test coverage, and found plenty for the testDiscovery class, but could not find any tests that actually check the
run-tests.shscript. If there are some tests, let me know where to find them, and I will add coverage for this bug if you'd like me to. Hopefully the description and debug output above is enough to see the problem and the correction.Comment #5
jonathan1055 commented#3251399-17: Drupalci.yml filtering for testgroups: 'scheduler,scheduler_api' does not run all the required tests demonstrates that this patch fixes the problem. I have applied it via
host_command. No tests are lost now - the previously missing ones are being included.Comment #6
nicxvan commentedComment #7
nicxvan commentedMoved to core queue per conversation on slack with longwave.
Comment #8
longwaveThe debug output in #3 is enough to convince me that the switch from
array_flip()toarray_keys()is the correct thing to do here. I don't think we have any test coverage of run-tests.sh itself.Comment #9
alexpottI think we can make this code way easier to grok. Without some flipping and array_keys()
Here's a code way to test this locally...
This should run 12 tests. Currently it runs 11 because of the flipping and the way array_flip works with duplicate values of test_class => 0.
Comment #10
nicxvan commentedAfter reviewing the patch it looks right to me, the added array unique should help prevent extraneous test runs too.
First I pulled down the default drupal core branch 9.5.x then I ran the command you provided. I received an error about needing phpunit prophecy for the version of php unit.
I ran composer require --dev phpspec/prophecy-phpunit
I'm trying to test this and it looks like it is working with the two changes made.
This is my first time running Drupal core tests so let me know if something doesn't look right in my results.
UNPATCHED COMMAND RESULTS
11 Tests run
PATCHED COMMAND Results
12 tests run
Comment #12
jonathan1055 commentedThanks for your work on this. Yes the new way of merging the classes is more readable that the flips.
I've just run a live test on #3049585-7: Check drupal.org testing infrastructure where I patched the project's drupalci.yml with patch #9 from above, instead of patch #4 that I had been using. The job correctly ran all the test classes in the requested groups, so it looks good. In agreement with @nicxvan so I'm marking this RTBC
Comment #14
catchCommitted/pushed to 10.1.x, cherry-picked back through to 9.4.x, thanks!
Comment #15
jonathan1055 commentedThank you that's great. Also good that you backported to 9.5 and 9.4
Comment #16
jonathan1055 commentedI have just tested Scheduler with 9.4.dev without the patch I had added in drupalci.yml and all the required test groups are being run, none dropped. Thanks for fixing this.