Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Port over cronRun to BTB from WTB. This could be a trait potentially.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#40 | 2795037-interdiff-31-40.txt | 566 bytes | gnuget |
#40 | 2795037-40.patch | 2.8 KB | gnuget |
#31 | 2795037-31.patch | 3.33 KB | shashikant_chauhan |
#31 | interdiff-25-31.txt | 1.27 KB | shashikant_chauhan |
#27 | 2795037-25.patch | 3.37 KB | jhedstrom |
Comments
Comment #2
dawehnerComment #3
dawehnerComment #4
jhedstromThis moves the method to a trait, and adds it to BTB.
Comment #5
jhedstromNote that this change to run cron directly from the service doesn't lose any test coverage, as the
CronRunTest
class tests running cron via the browser.Comment #7
jhedstromHmm. Not sure about those fails. I can reproduce some of them locally on 8.3.x w/o this patch...
Comment #8
jhedstromApparently there's something special happening when cron is run via the browser. This switches the new trait to behave as the old method did. Perhaps we should add a follow-up to figure out why the direct call to the service fails.
Comment #10
jhedstromOops.
Comment #11
dawehnerI'm wondering whether we should add dedicated test coverage for it?
I'm also wondering whether going to the URL vs. calling the API function itself is worth thinking about.
Comment #12
jhedstromIt would be readily unit-testable if the trait were able to call the service directly. I'm not sure if we need to tackle that in this issue though, as that could be a follow-up. The implicit usage of the trait seems like sufficient testing for this pass?
Comment #13
dawehnerEverytime people argue for not writing tests I think we should listen and explicitly try to write a test for it.
Comment #14
jhedstromI think I was over-thinking the way a test would look. That test works perfectly :)
I still cannot figure out why invoking cron from the browser has a different effect that calling the service directly.
Comment #15
dawehnerWell, we can figure that out later.
Comment #16
klausiwe should avoid using \Drupal where we can to not set a bad example. We have the container on both classes using the trait, so this should be $this->container->get(..)
Comment #17
klausiComment #18
Sonal.Sangale CreditAttribution: Sonal.Sangale at Blisstering Solutions, Iksula commentedComment #19
dawehnerSo what about just adding a BC class, which has all the traits we ever need: #2820182: Add a LegacyBrowserTestBase which uses every legacy trait we have while keeping the main class at least sort of free of crap?
Comment #20
jhedstromMeaning here we would just introduce the trait, but not have
BrowserTestBase
use it, and allow other tests to use it as-needed?Comment #21
dawehnerYeah to be honest.
Comment #22
jhedstromI've switched the trait to use the container instead. I also added a response assertion, as locally I was seeing failures when I had accidentally turned off the http server it was running on, and couldn't figure out immediately why the test was failing.
Comment #23
dawehnerI was wondering whether the response code condition should be moved to the actual test of this method, so its not there everytime.
Comment #24
jhedstromI could go either way on this. Having it in the trait makes failures more verbose if some other test is breaking the cron callback for whatever reason. If it's only in the test, then cron running could potentially silently fail in other tests. However, the old method did not have this check, and it's been fine thus far :)
Comment #25
dawehnerIMHO we should keep these issues as straightforward as possible:
Comment #26
dawehnerSee #2820182: Add a LegacyBrowserTestBase which uses every legacy trait we have
Comment #27
jhedstromMakes sense. This does everything except script conversion and follow-up. When adding the follow-up, we should also perhaps explore why calling the service directly behaves differently from using the page controller too.
Comment #28
dawehnerCool, perfect!
Comment #29
alexpottThere is a whole debate going on about the use of $this->container vs \Drupal in tests... Can we not make this change here. The debate is not yet finished and the way forward is unclear. See the latest comments on #2066993: Use \Drupal consistently in tests.
Comment #30
klausiChanging the line back to use \Drupal is a novice task.
Comment #31
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commentedAdding patch.
Comment #32
shashikant_chauhan CreditAttribution: shashikant_chauhan as a volunteer and at Iksula commentedComment #36
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI have applied and tested patch #31 and it solves the problem. I have just started converting the Scheduler module 8.x tests to use BrowserTestBase not WebTestBase. I was getting
Call to undefined method Drupal\Tests\scheduler\Functional\SchedulerFunctionalTest::cronRun()
. But with the patch this is fixed. I know that the core automated tests are all passing, but it does no harm to have a real user also confirm that this fixes a contrib test too.The interdiff 25 to 31 looks fine, but someone with more experience than me should re-mark this issue as RTBC.
Incidentally. I had to add both
use Drupal\Tests\Traits\Core\CronRunTrait;
to the file anduse CronRunTrait;
to my test class. First I was expecting that BrowserTestBase would have done this for me, and I would not have to make these additions, but I think reading #25-27 above this is what is expected and all is OK.Comment #37
dawehnerWorks for me for now.
Comment #38
gnugetThis looks great to me as well.
RTBC to me. +1.
Also, the Novice part was done, so removing the tag.
Great work, thanks!
Comment #39
dawehnerThis change is no longer needed
Comment #40
gnugetAlright.
I did a straight reroll of 31
And also added the change mentioned in #39.
Patch attached.
Comment #41
dawehnerThank you @gnuget!
Comment #42
alexpottI'm not a huge fan of adding more and more methods to BTB even via traits. It feels like we're just going to end up back in WebTest land with a method for everything. But since this is blocking #2735005: Convert all Simpletest web tests to BrowserTestBase (or UnitTestBase/KernelTestBase) and that goal is far more important than my reservations...
Committed b8d54ee and pushed to 8.3.x. Thanks!
Comment #44
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks for the work and the commit.
Is this also going to make it into 8.2.x?
Comment #45
dawehner... well we are not doing that. There is nothing in this patch touching
BrowserTestBase
...Comment #46
alexpott@dawehner how right you are... alexpott--
Comment #47
dawehner@alexpott my inner alexpott won against your outer alexpott
Comment #48
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedJust wondering if my question from #44 got overlooked:
Comment #49
alexpottTasks in general don't go into 8.2.x - but arguably test tasks that are additions should so you can write tests against both 8.2.x and 8.3.x.
Comment #50
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks alexpott, yes that is exactly what I was hoping for. I've already had to write a workaround to allow us to convert our WTB tests to BTB and to commit them. This workaround is now not required at Core 8.3 but it still required at 8.2. I (and I assume many likewise) develop and test my contrib code at both 8.2 and 8.3 and both versions are used in our automated testing on D.O. It would help many other contrib test writers to be able to convert to BTB at 8.2
Comment #53
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedThanks @alexpott for agreeing that this does need to get into 8.2. Marking as 'patch to be ported' to Core 8.2.x-dev as per comments #48 to #50.
I know that 'patch to be ported' is not exactly right, but it is the closest status for the situation, and leaving it as 'Fixed' will mean it could get forgotten for two weeks and then closed.
Comment #54
alexpottThis is not going to happen 8.2.x has just entered commit freeze for 8.2.6 and this is not important enough to break that. It is not part of both 8.3.x and 8.4.x so everything is good.
Comment #55
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedSo are you saying that 8.2.6 is the final 8.2 release and that all 8.x core work will only be done at 8.3 (and now 8.4) ? I tried to search for this announcement on D.O. but found nothing.
Comment #56
dawehnerhttps://www.drupal.org/core/release-cycle-overview and https://groups.drupal.org/node/515932 are the two pages you probably want to read.
Comment #57
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedOK thanks for those links. I can see now that 8.2.6 will be the final 8.2 release.
I've put the issue version back to 8.3.x as that is where it was fixed.