Major only as it makes performance improvements in the test base more difficult.
Problem/Motivation
#2747075: [meta] Improve WebTestCase / BrowserTestBase performance by 50% would like to change WebTestBase to allow caching per installation and installed modules and custom.
That can potentially speed up local development a lot.
A soft blocker for that is that all changes need to be done twice.
One part that makes BrowserTestBase / WebTestBase difficult to maintain is that many functions are identical in both classes, but play only an utility function.
Another part is that the installDrupal() function contains all the little sub-functions inline that the original function called as several helper functions.
BrowserTestBase is - after working a little with it - harder to read in that respect and we generally prefer many little helper functions doing one thing properly each.
(It is not immediately obvious, but after working with the code flow of WebTestBase for a while, the similarity can be seen.)
Untangle that back to the original helper functions and move it to the trait, ensure to not break BC of BrowserTestBase by resolving conflicts.
Proposed resolution
- Move identical functions to a trait in the core/tests space that are shared by both classes.
- Untangle installDrupal() of BrowserTestBase again to go back to the old structure of setUp() in WebTestBase.php, which called lots of helper functions.
- Move all those helper functions to the trait as well.
Remaining tasks
- Do it
| Comment | File | Size | Author |
|---|---|---|---|
| #63 | 2796105-followup.patch | 906 bytes | tstoeckler |
| #54 | 2796105-54.patch | 74.58 KB | alexpott |
Comments
Comment #2
fabianx commentedComment #3
fabianx commentedList of methods that should be the same (from visual memory):
- prepareDatabasePrefix
- changeDatabasePrefix (90% identical)
- prepareSettings
- writeSettings
- rebuildContainer
- prepareRequestForGenerator
- resetAll
- refreshVariables
- setContainerParameter
AND:
installDrupal() replacing / hardcoding:
- initUserSession();
- doInstall
- initSettings
- initKernel
- initConfig
- installModulesFromClassProperty
- rebuildAll (to be deprecated in #2795789: Do not rebuild the container so often in BTB, so don't bother with the part calling resetAll())
TestBase.php - not that interested, just here for completeness
- prepareEnvironment (70% similat in TestBase.php)
- getConfigSchemaExclusions
Comment #4
larowlanComment #5
larowlanlet's see what blows up with this first attempt
Comment #7
larowlanwhoops - got the inheritance slightly wrong
Comment #8
larowlangah, muppet
Comment #11
larowlanstill changing the inheritance
Comment #13
larowlanpassRaw pass_raw mismatch
Comment #14
dawehnerHere is a conceptual question. If you look into
TestSetupTraitandBrowserTestBaseyou see BTB overridingprepareDatabasePrefix.This feels weird, because simpletest is the one that does actually more. Maybe we should move the override to WTB?
Nitpick: out of scope change :P
This is really nice code, IMHO
Comment #15
fabianx commentedThis is really great work! Thanks so much for this cleanup!
I agree the code of installDrupal() is really nice to read now!
Comment #16
larowlanaddressing feedback
Comment #17
larowlankilling time √
Comment #18
fabianx commentedRTBC - Looks great to me!
Comment #19
dawehnerSuper nice work! This trait could be of course improved, but that would be out of the scope of this issue.
Comment #21
fabianx commentedNeeds a reroll
Comment #22
yogeshmpawarI have rerolled the patch for 8.3.x branch.
Comment #23
fabianx commentedBack to RTBC, thank you #22!
Comment #24
naveenvalechaComment #26
fabianx commentedThis needs a reroll, but this might be a little more complicated.
Comment #27
yogeshmpawarComment #28
yogeshmpawar@Fabianx - I have rerolled the patch to work with 8.3.x version.
please review
Comment #30
dawehnerJust a reroll as part of the research of moving
UpdatePathTestBaseComment #32
fabianx commentedAssigning back to larowlan in the hopes he can fix the test failures.
Comment #33
sam152 commentedFix attached.
Edit: not actually sure why this works. I guess $this->$key = $value in UserSession::__construct isn't enough?
Comment #34
sam152 commentedComment #35
sam152 commentedAh, figured it out. So, passRaw is required by btb and pass_raw is required by wtb. This is also referenced in UserCreationTrait:
Comment #36
dawehneroh right, we've been there already biting us. Its good to have that so we have a better BC layer.
Thank you @Sam152 for the reroll!
Comment #37
fabianx commentedThanks, I think we are back to RTBC.
Comment #39
fabianx commentedThis needs a reroll
Comment #40
anish.a commentedRerolled
Comment #41
fabianx commentedBack to RTBC
Comment #43
anish.a commentedI assume it was a random failure. Back to RTBC.
Comment #44
fabianx commentedAdding tag.
Comment #45
alexpottChange of scope - is that really right? Can a trait add a private method - I think it can. I'm not sure though.
I think FunctionalTestSetupTrait should use TestSetupTrait so things like container are declared and I think you'd always want TestSetupTrait if you're using FunctionalTestSetupTrait.
Missing new line.
Comment #46
fabianx commented#45: Thanks so much for the review:
I confirmed that traits can use private functions:
https://3v4l.org/m3NC9
Thanks!
Comment #47
larowlanfirst a reroll
Comment #48
larowlan1) agree
2) done
3) if I do that, I get
Drupal\simpletest\TestBase and Drupal\Core\Test\FunctionalTestSetupTrait define the same property ($configSchemaCheckerExclusions) in the composition of Drupal\simpletest\WebTestBase. However, the definition differs and is considered incompatible.i.e. TestBase in simpletest already includes the TestSetupTrait. So, in summary WebTestBase gets TestSetupTrait via inheriting it from TestBase. BrowserTestBase gets it from using both TestSetupTrait and FunctionalTestSetupTrait. Unfortunately, we're stuck with the deprecated KernelTestBase until 9.x, so until then, we can't get rid of TestBase and make TestSetupTrait used by FunctionalTestSetupTrait.4) done
Comment #49
larowlanparaphrasing #48.3
Comment #50
fabianx commentedBack to RTBC, it would be great to get this in to unblock other work.
Comment #51
dawehnerThis certainly belongs into the phpunit initiative
Comment #52
larowlanThanks @dawehner
Comment #53
alexpottUnused apart from in docs. And these docs need improving since they all point to TestBase but they need to point to both
Drupal\simpletest\TestBaseand\Drupal\Tests\BrowserTestBaseSo is this method only used by WebTestBase? I think the main use is
\Drupal\Core\Test\FunctionalTestSetupTrait::rebuildAll()which is called by bothWebTestBase::setUp()andDrupal\Tests\BrowserTestBase::installDrupal()Lovely let's get rid of all these uses then!
Comment #54
alexpottComment #56
alexpottNever seen that fail in
Drupal\filter\Tests\FilterFormatAccessTestbefore - retesting.Comment #57
fabianx commentedNice changes! Thanks for the review and great work finding those.
Back to RTBC!
Comment #58
alexpottCommitted d2b4642 and pushed to 8.3.x. Thanks!
Comment #60
fabianx commentedTime to celebrate! Thanks, Alex!
Comment #62
frankcarey commentedGreat work, Contrats!
Comment #63
tstoecklerUnfortunately this caused a regression:
WebTestBaseused to use$this->originalSitefor the original site path whileBrowserTestBaseused$this->originalSiteDirectory. This is used to determine the path for thesettings.testing.phpandtesting.services.ymlfiles which can be used to influence the child site of the test.While the reading of this value was consolidated in this issue to always read from
$this->originalSitethe setting of$this->originalSiteDirectoryinBrowserTestBasewas not updated accordingly.Even though this is a regression between 8.2 and 8.3 I would personally propose not rolling this back for the reasons below, but posting the fix here instead of a new issue in case maintainers do think reverting is the best way to go:
settings.testing.phpandtesting.services.ymlComment #64
cspitzlayI can confirm that the patch from #63 solves the test failure we had on our CI system that was due to our settings.testing.php not being found.
Comment #66
tstoecklerTestbot says:
18:25:12 Cannot connect to the Docker daemon. Is the docker daemon running on this host?Next try.
Comment #67
cspitzlayThe patch fixes the regression and the test is green -> RTBC.
Comment #68
tstoecklerMoved to #2849222: settings.testing.php / testing.services.yml not picked up by BrowserTestBase per @alexpott. Re-closing.