Problem/Motivation
Improve readibility.
Get closer to allow converting the script to a Symfony console application command.
Proposed resolution
Introduce a Configuration class, and let it do the command line arguments parsing, via Symfony Console's components.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | run-tests help new.png | 2.23 MB | jonathan1055 |
| #23 | run-tests help before.png | 1.36 MB | jonathan1055 |
Issue fork drupal-3536964
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:
- 3536964-11.x
changes, plain diff MR !15468
- 3536964-pp-4-change-run-tests.sh
changes, plain diff MR !12787
Comments
Comment #3
mondrakeComment #4
mondrakeComment #5
mondrakeComment #6
jonathan1055 commentedI've not done a full review, but the first thing that struck me were the many changes from
$args('the-string')to$input->getOption('the-string'). In fact there are 73 of these, and I suggest it would be more readable if the $args array was retained, and simply built by the necessary calls to $input->getOption() but doing each only once. This would also reduce the compexity of the MR, and make it possible to print the entire $args array when doing debug. But having looked now at more of the changes, maybe my idea is not so important and stick with what you have done. But the diff is massive and needs a lot of checking. I can try to use this in a Contrib pipeline to test, but I expect the Core tests are doing enough to verify it already.Comment #7
mondrakeThank you. My final idea here would be to add a separate class holding all the configuration of the test runner - mimicking somehow what PHPUnit or Paratest are doing. That would include processing of the CLI arguments but also of the ENV varaibles that right now is spread in many places. But that would be even bigger change... so here it's a transitional state.
Anyway... sorry to bump you across the issue hierarchy, but #3515347: Reduce run-tests.sh complexity in spawning subprocesses would need to be done prior than this as that one will remove some of the CLI arguments and make this one simpler.
Comment #8
mondrakeComment #9
mondrakeComment #10
mondrakeComment #11
jonathan1055 commentedAdding to meta parent
Comment #13
jonathan1055 commentedUnblocking this, now that #3515347: Reduce run-tests.sh complexity in spawning subprocesses has been done. Thanks for workig on that one, it's good to have some progress.
Comment #14
mondrakeComment #15
jonathan1055 commentedFrom #7
Is that what the most recent commit does?
I will also use this MR in a contrib test, but as I said in #6 if the Core tests run OK then that's probably enough?
Comment #16
mondrakeNope - it's diluted in the rest of the MR, and the merge swallowed the change. The change that happened in #3515347: Reduce run-tests.sh complexity in spawning subprocesses was that the internal
--test-idand--execute-testoptions were removed, so we no longer have to take care of them in the MR here.Actually I think there's other code that may be dead now, will try to check on it later today. But I assume that won't change the essence of the MR here.
Testing in contrib would be great - maybe it could be tested also in combination with using the
--sqlite ":memory:"argument that was introduced in the parent.Also some manual testing would be good - in CI contexts this is probably doing what expected, but the script itself has other options like
--list,--list-files,--helpetc etc. I did try myself and all seems to work OK, but the script here has no test coverage so one more hand would help.Comment #17
jonathan1055 commentedI've tested this in a Contrib CI pipeline, using the diff from this MR to patch run-tests.sh. If anyone else would like to use this I have attached the addition for your .gitlab-ci.yml file. I think it needs to be used in the 'next minor' variant, which runs 11.4-dev as the patch might not apply in 11.3.2
Here's the pipeline, running one functional test, one functional javascript and one kernel test
https://git.drupalcode.org/issue/scheduler-3356800/-/pipelines/727371
I've compared the three logs with the regular non-patched version, and they are identical in output. The only change we see is that the php binary is now shown as /usr/bin/sudo wheras before it was /usr/local/bin/php
I have also run it with the addition of
--sqlite ":memory:"as requested.Pipeline https://git.drupalcode.org/issue/scheduler-3356800/-/pipelines/728118 shows it is used in the command here. Again the three output logs are identical to before.
Comment #18
mondrake#17 you may want to remove
--php "/usr/local/bin/php"from the run-tests.sh command line. This is now irrelevant (I also marked it deprecated in the MR here), independently from this issue. Passing a PHP executable path was relevant before #3515347: Reduce run-tests.sh complexity in spawning subprocesses because that one PHP executable was used to spawn sub-processes of run-tests.sh itself. Since the commit of the parent this is no longer happening (run-tests.sh spawns PHPUnit CLI sub-processes directly), so the option and its processing is just dead code now, that this MR is removing.Comment #19
mondrakeAnyway,
PHP Binary...........: /usr/bin/sudoin the initial output feels rather wrong, even if it's there just as info at this point. It's pointing to the sudo path under which the script is being run in the CI context, not the path to the actual PHP binary.
Maybe we can use PhpExecutableFinder from symfony/process to give us more accurate info.
Comment #20
mondrakeNow using PhpExecutableFinder from symfony/process to determine PHP's executable path.
Comment #21
jonathan1055 commentedThanks for the info. The Gitlab CI job has
--php "$(which php)"in the command line when executing run-tests.sh, so it sounds like this is redundant with this new chnage?. This part of the job template is used for all variants, so it may be the case that we leave it in for now, because these run-tests changes won't be back-ported to Drupal 10. Or we could check the core version and add that snippet conditionally, which might be a better solution.I've tested the updated MR, and also removed the
--phpparameter, and now we get back the originalPHP Binary...........: /usr/local/bin/phphttps://git.drupalcode.org/issue/scheduler-3356800/-/jobs/8289782#L593
Comment #22
mondrakeYes - the option is still accepted, but its a no-op.
The endgame is the same, but behind the scenes it's no longer the input resulting from
--php "$(which php)", it's the output ofPhpExecutableFinder::find().Comment #23
jonathan1055 commentedYes, that is what I meant. All's good.
You also asked for manual testing of
--listand--list-files. They both give the results for all tests in all modules, as intended. But adding--directory=modules/mymoduledoes not reduce the output, we still get everything. This is not only very slow, but also (as reported elsewhere too) if any other 3rd-party contrib project causes deprecations due to missing classes, then the whole command fails. It would be great to have--directory=not ignored in these cases. But maybe that work will be done in #3549601: Allow --directory and @group to work together in run-tests.sh next, after this issue.The
--helpformatting is greatly improved. Much better use of the screen give more info without scrolling. I have also checked the text changes, and apart from moving some options, and the extra info such as defaults, these are the differences:--phpunit-configurationand--ci-parallel-node-total--phpNote that ':memory:' cannot be used, because this script spawns sub-processes. However, you may use e.g. '/tmpfs/test.sqlite'This argument must be last on the command line.So that all looks good.
Comment #24
smustgrave commented@jonathan1055 would you say this one is ready?
Comment #25
jonathan1055 commentedI have done the Contrib testing, both in Gitlab pipelines and locally, and all seems OK. However, I don't pretend to understand the actual coding changes that Mondrake has made. I am assuming that if the core tests run, and contrib too, then in principle it is working.
Just a couple of points:
It would be good not to lose sight of this. I don't know if that is a separate issue or not.
NW for these things, but otherwise if Mondrake is confident then yes lets get this moving onwards :-)
Comment #26
mondrakeThanks guys
#25.1 - it's done, it's the
Configurationclass introduced in https://git.drupalcode.org/project/drupal/-/merge_requests/12787/diffs?c... and then tuned later#25.2 - it's done, in https://git.drupalcode.org/project/drupal/-/merge_requests/12787/diffs?c..., the --php option and finding the PHP executable is no longer necessary
#25.3 merged the suggestions
edit - removed the 'Needs manual testing' tag given the extensive tests done by @jonathan1055
Comment #27
jonathan1055 commentedThanks for the info and commit links, and for adopting my suggestions. The help looks good now.
I had not tested the
--classoption before, so now have done that. Two small observations--class MigrateSchedulerDataTestfails to find the class, but--class 'Drupal\Tests\scheduler\Kernel\MigrateSchedulerDataTest'does work. If this is intended then maybe the help should state that?--fileoption. I've made a MR suggest for this.Then let's call this RTBC. I presume it is only for 'main' and 11.x, so will affect 11.4.x but not 11.3.x ? Just want to know what audience this could impact if any problem has not been noticed.
Comment #28
mondrake#27.1 this MR is not changing that behavior. Clarified that FQCNs must be indicated.
#27.2 I do not think quotes are necessary, rather blackslashes need to be escaped on the command line (i.e.
php ./core/scripts/run-tests.sh --url http://example.com/ --class Drupal\\Tests\\block\\Functional\\BlockTestis ok,
php ./core/scripts/run-tests.sh --url http://example.com/ --class Drupal\Tests\block\Functional\BlockTestis not. Also added a comment for that.
Finally, replaced text that indicated
@group annotationswith the new#[Group()] attributesinstead. See #3556580: Remove remaining references to @group annotations from tests.Comment #29
jonathan1055 commentedThank you for the clarifications in the help. Yes you are right, quotes are not specifically required, that was just my first attempt at solving it and it worked. But backslahes also work, so it's good you have that in the help.
I will be brave and mark this RTBC, but I really do not know if we've tested every option. I guess that may become apparent if things break.
Do you have a plan for which branches this will be merged into? re my last question on #27.
[edit: the last addition to help needs a linebreak. I have added that in a MR suggestion]
Comment #30
mondrake#27/#29 that's a call for core committers. A related issue #3515347: Reduce run-tests.sh complexity in spawning subprocesses was committed to main and 11.x, I would be surprised if this one would get any further.
Comment #31
jonathan1055 commentedGood, that's what I was expecting.
Comment #32
longwaveAdded some question/feedback, it's hard to know where we are done here, ideally one day this will be a fully fledged class implementation of a console command and this is a good step on the way.
Comment #33
mondrakeAddressed @longwave feedback (thanks!) apart one point I was unclear about.
Comment #34
mondrakeWe may want to move parts of
simpletest_script_init()to the newConfigurationclass, but I would do that in a follow-up. I was already thinking we need to manage config keys independently from the args/options coming from the CLI - and enable configuration via a yml file.Comment #35
longwaveI read the docs and I think we can set the defaults once, see MR comments.
Comment #36
mondrakeComment #37
mondrakeOK, but if you do specify the option, without then indicating a value, it's a failure. So now the Build job fails because it does not indicate a
parallelkey and the corresponding$CI_NODE_INDEXand$CI_NODE_TOTALenv variables are missing so from the CLI there is no value associated with the option. It's a bug that we can fix adding the vars explicitly, but may impact scripts out there in the wild.Comment #38
mondrakeNeeds to figure out what to do.
Comment #39
longwaveI think that's fine, it feels like an error to specify the option without a value anyway?
Comment #40
mondrakeComment #41
mondrakeI see failures when run locally, working on it.
Comment #42
mondrakeThe local failures are unrelated - that will be another issue. Rebased and back to NR.
Comment #43
mondrakeRebased due to merge conflicts.
Opened #3579253: run-tests.sh does not properly process PHPUnit output when no test are executed for a class for #42.
Comment #44
mondrakerebased
Comment #45
longwaveThis is interesting because it might converge with #3453474: CLI entry point in Drupal Core soon...
Comment #46
mondrake#45 yes!
Comment #47
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. 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.
Comment #48
mondrakerebased
Comment #49
amateescu commentedReviewed the MR, found a bug and a minor improvement that can be ignored if not desired. Feel free to self-RTBC afterwards.
Comment #50
mondrakeThanks, done as suggested and actually made the help text be displayed when no arguments are in the command line. Self-RTBCing per #49.
Comment #52
amateescu commentedCommitted afcf201 and pushed to main. Thanks!
Not sure whether this one should go into 11.x as well. I see that the related issues were backported, so I'll ask around.
Comment #54
amateescu commentedDiscussed with release managers and we think it should be backported to 11.x.
Comment #57
mondrake11.x port.
Comment #58
smustgrave commentedSeems like a good rebase.
Comment #59
amateescu commentedCommitted 45c8034 and pushed to 11.x. Thanks!
Comment #62
longwaveLooks like the push didn't make it to 11.x.
Comment #64
amateescu commentedOops :)
Comment #66
jonathan1055 commentedThank you for porting this back to 11.x. It is used in the 'Next Minor' Gitlab pipeline varaint, which uses 11.4-dev, so the changes will get used and tested for real.
I did notice something in the help, which might be a typo, or it might be my mis-understanding. The help for
--suppress-deprecationssaysIn that last line, should it be "any unexpected unsilenced deprecation error will fail tests". If the deprecation is silenced then I would not want the test to fail. It's the unsilenced ones that we need to be alerted of. At least, that's my understanding. Please correct me if I'm wrong.
Comment #67
mondrake#66 assuming that we mean
silenced deprecation ===
@trigger_error(..., E_USER_DEPRECATED);, andunsilenced deprecation ===
trigger_error(..., E_USER_DEPRECATED);then I think that currently that does not make any difference in PHPUnit 12. This is somehow a text that dates back to when the Symfony PHPUnit bridge was in and deprecation reporting was managed there.
What the option does now is managed in
PhpUnitTestRunner::prepareCommand(), and how this interacts with the PHPUnit CLI command spawned by run-tests.sh:--suppress-deprecationsis specified => PHPUnit CLI is spawned with env variable'SYMFONY_DEPRECATIONS_HELPER' = 'disabled'and NO fail switches for failing on deprecation. This essentially means deprecations may be reported in raw logs, but they are not failing the test overall.--suppress-deprecationsis NOT specified => PHPUnit CLI is spawned with env variable'SYMFONY_DEPRECATIONS_HELPER'inheriting from parent, and with--fail-on-deprecationand--fail-on-phpunit-deprecationfail switches specified. This essentially means deprecations lead to test failure UNLESS they are ignored by the patterns in the.deprecation-ignore.txtindicated by the SYMFONY_DEPRECATIONS_HELPER variable.To complicate things:
SYMFONY_DEPRECATIONS_HELPERisdisabledand--suppress-deprecationsis NOT specified: this means ALL deprecations are failing tests;PHPUNIT_FAIL_ON_PHPUNIT_DEPRECATIONenv variable is set to TRUE and--suppress-deprecationsis NOT specified: this means PHPUnit own deprecations (those that PHPUnit itself is throwing) are not failing tests.We probably need to sort this out a bit - the confusion IMHO is driven by the fact that PHPUnit's options are positive (i.e. need to be set to FAIL tests) whereas run-tests.sh one is negative (i.e. needs to be set to PASS tests).
EDIT - sorry I was initially swapping silenced with unsilenced