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
This is step 2 for #2447573: [meta] Make sure 8.x - 8.x hook_update_N() testing is possible.
Proposed resolution
The script/db generated from #2497323: Create a php script that can dump a database for testing update hooks will be loaded by the tests, update hooks will be run, and changes can then be asserted by the tests.
Remaining tasks
Create anupdateTestBase
that loads the database via setUp().Write a test that tests the loading of the db (most likely via an update hook in one of the test modules)- Write a few tests that alter tables that are part of the db dump (node, users, etc).
RefactorWebTestBase::setUp()
so it is easier to override without code duplication- Figure what else, if anything, needs to be tested in this patch
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#43 | test-updates-2498625-43.patch | 141.03 KB | jhedstrom |
#43 | test-updates-2498625-43-do-not-test.patch | 26.73 KB | jhedstrom |
Issue fork drupal-2498625
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
Comment #1
jhedstromThis patch starts a very basic test (without the db script) wherein the schema of the test module is manipulated by the State API. It is failing because the updates aren't run properly when run from WebTestBase (a site under maintenance mode error).
Comment #3
jhedstromThese tweaks get the update hooks firing.
Comment #4
jhedstromThis adds the script being generated over in #2497323: Create a php script that can dump a database for testing update hooks, and the beginnings of a test base (some copied from the old D7 version). The database is succesfully loaded into the test environment, but then the
setUp
method is currently failing when writing out to a cache (it appears to be attempting to write *all* config to thetyped_config_definitions
cache), and gets the following error:Comment #7
jhedstromThe error in #4 has been resolved over in #2497323: Create a php script that can dump a database for testing update hooks.
This patch loads the db generated from that script, and runs some very basic tests.
Comment #8
jhedstromSpoke with Webchick in IRC, and since this is blocking a critical, it's also a critical.
Comment #9
jhedstromComment #10
dawehnerSo does this throws an exception somehow? I'm curious what happens on hosts without zlib
I see some similarity to WebTestBase ... is there a sane way to extract things in a method so you don't have to duplicate everything? If you say its too complex and would make the patch way harder, don't do it, but I'm just curious here.
Comment #11
jhedstromYeah, let's try to refactor
WebTestBase::setUp()
while we're at it--duplicating that much code is really unnecessary.Comment #12
jhedstromThis is a first attempt at refactoring
WebTestBase::setUp()
. This makes it much cleaner to override inUpdatePathTestBase::setUp()
.The
runUpdates()
method will now fail the test if this library isn't present (taken directly from the 7.x version).Unassigning for now as I will be away most of the weekend.
Comment #13
jhedstromThe 'do not test' patch in #12 is incorrect. This one contains the changes to
WebTestBase
.Comment #15
jhedstromFixing an obvious error in the refactoring.
Comment #17
jhedstromThis time!
Comment #19
larowlanSo ToolbarCacheContextsTest already has a protected installModules with a different signature.
So I've renamed it to installExtraModules() because the use-case is different.
Can you add the interdiff on top of your branch @jhedstrom and add a new do-not-test patch?
Comment #20
dawehnerOh that is tricky :)
Comment #21
webchickSince this is a sub-issue of #2447573: [meta] Make sure 8.x - 8.x hook_update_N() testing is possible, which is a D8 upgrade path blocker, tagging as such.
Keep up the fantastic work! :D
Comment #22
webchickMore metadata adjustment. Almost done, I swear...
Comment #23
jhedstromHere is the corresponding do-not-test patch for #19.
Once #2497323: Create a php script that can dump a database for testing update hooks lands, we'll want to regenerated the gzipped dump in this patch.
Comment #24
jhedstromOops, the patch above didn't include the actual changes from #66.
Comment #25
jhedstromGaaah. This time!
Comment #26
jhedstromComment #27
jhedstromNow that #2497323: Create a php script that can dump a database for testing update hooks has landed, this is the same patch as #19, but with the updated db (no interdiff since the do-not-test patch in #25 still the same).
Comment #28
dawehnerGreat work so far! Some small points.
It adds quite some test coverage, which is great!
What about name it a bit more specific? installModulesFromClassProperty?
Do you mind expanding the comment describing what you changed from the original?
Should we do that maybe in the constructor?
Nitpick: Missing dot at the end
Well its a setting so it can't be. I think this is fine
Do you need it to be external? I think this should work without it
Nitpick: newline
Isn't it possible to put all that into a property on the object?
Should we add a suffix like beta_11, so its clear at which point this file got generated? Especially for system I could image that new update_N hooks are created
Let's make them public ... technically protected works but it won't in case you would use phpunit as test runner
Do you think we can test a bit more here, is it worth to do?
Let's make it a public function
What about not using +1 but name the variable $schema_version and check for >= 8001?
Comment #29
jhedstromWorking on #28.
Comment #30
jhedstromThis addresses all the points in ##2 except for the following.
__DIR__
when defining a class variableI didn't add a suffix, but added
.beta11.
in the middle--I wonder if the script itself should be regenerated from beta11 instead of current HEAD?Testing the homepage was a very easy way to ensure the db was properly loaded and the site was working (I used this test while working on all the code in
setUp()
. I think it's worth leaving.Comment #31
jhedstromComment #32
dawehnerThank you for your quick response!
Sadly your interdiff.txt is empty ... I'll just trust you :P
Oh PHP!
I think for now its fine to use HEAD. Mh, maybe we should use the git commit hash instead? Do other people have an opinion about it?
For now this feels good enough though.
Oh yeah I think testing that for example config worked is not a bad thing at all.
Comment #33
jhedstromInterdiff for the sake of thoroughness :)
Comment #34
dawehnerThank you!
I think someone with more knowledge of simpletest should have a look at it, but the split up of the setUp() method seemed to be reasonable for me.
Let's RTBC so alex can't have an excuse to not look at it :P
Comment #35
webchickOn the beta11 filename thing, in D7 these dump files weren't versioned. Which IMO is a good thing because we would now have at least 37 * 2 * 2 = 148 copies kicking around (one for each version of D7 * number of install profiles * filled/base), the 7.x-dev tarball would be ginormous. :(
We also do not seem to have any process for updating those dump files, since e.g. http://cgit.drupalcode.org/drupal/log/modules/simpletest/tests/upgrade/d... has not been updated since its initial commit in 2011, despite over 30 releases since then.
So I'm curious where this is coming from, since it's effectively a "new" feature to the upgrade test system to keep versioned database dumps, and not a feature I'm sure we want. What I would expect in D8 is prior to tagging each new minor version we'd just re-dump from the previous minor, and overwrite the existing file's contents (
drupal-8.bare.standard.php.gz
or whatever). There's no need IMO for core to support an upgrade path from 8.0.0 => 8.5.0 (or beta10 => beta14 or whatever) directly.Comment #36
dawehnerI'm confused, we don't talk about making snapshots more often, but well, we can just ignore that part :|
To be clear, there is no point in updating them. At some point you create the dump, for which you target for the
hook_update_N
function.Comment #37
catchOn database dump versioning:
In Drupal 7, we have two basic tests:
1. Test a full update from Drupal 6-7. Each time a new update function is added to Drupal 7, that would be covered implicitly. i.e. if you drop a Drupal 6 database into a Drupal 7 installation, hit update.php, then every update for any module in the D6 db will be run.
2. Test 'some version of Drupal 7' to 'the latest version of Drupal 7'. This will also test all the hook_update_N() added after the schema version of that dump.
There is a use case for versioned database dumps, but it's very limited:
Beta 12 is released. There is a new regression in the the schema (or actual data is corrupted) and an upgrade path is added which updates beta < 11 sites to the bad schema/data.
Beta 13 is released, the regression is fixed, and we add an upgrade path to migrate sites with the bad beta 12 schema.
Beta < 11 site, skips beta 12 and updates straight to beta 13 - never has the bad schema.
Beta < 11 site, updates to beta 12, then to beta 13 etc. - updates to, then away from , the bad schema
New install on beta 12 - starts off with the bad schema.
The upgrade path added in Beta 13 then has to differentiate between databases which have the schema defect, vs. ones that don't.
This isn't a theoretical situation - we had exactly such a bad update in the Drupal 6-7 cycle (at least one) which was a nightmare to fix.
Another issue is if we start to drop support for direct updates from older versions. For example we might not support upgrading Drupal 8.0.0-beta14 all the way to Drupal 8.4.6 - we might instead say you have to go 8.0.0 0 -> 8.1.6 -> 8.2.6 -> 8.3.6 -> 8.4.6 sequentially.
In such a case, the old database dump will start getting hook_update_last_removed() errors and we'd need a new one. But then we'd probably not keep the old one around (except to assert that error possibly).
In general we can assume that sites have identical schemas when they update between releases, so the 'starting' database version is OK and as we add more updates they'll be run on top of the old ones - until it isn't.
However documenting that the 'starting' dump comes form a particular version in the naming seems OK to me. But also since we don't support updating from the beta, we'll probably need to keep updating it until we get to release candidate, then stick from then onwards unless something comes up.
Leaving RTBC for now, but we're so, so out of practice having to deal with this, it'd be good to ensure everyone's on the same page.
Comment #38
alexpottContainerInterface.
environmentl
Missing an empty line between @param and @return
Missing @param and should be ContainerInterface
Comment #39
webchickThe branch maintainers agreed this is obviously critical, so tagging.
Comment #40
jhedstromThis should address the tweaks from #38. I've left the beta11 part of the filename for now.
But that is part of the goal of this issue :)
#2341575: [meta] Provide a beta to beta/rc upgrade path.
Comment #41
jhedstromComment #42
dawehnerLet's put a one-line description on there
Comment #43
jhedstromThere were a few places w/o a description for that parameter.
Comment #44
dawehnerThe feedback from alex and myself got adressed
Comment #46
catchOK I'm happy with this, so went ahead and committed/pushed to 8.0.x, thanks!
We can revisit the database dump naming since we'll need a fresh database dump from the day we start supporting the upgrade path (next beta or the one after most likely).
Comment #47
stefan.r CreditAttribution: stefan.r commentedJust a heads up, importing the beta11 schema with the patch in #1314214: MySQL driver does not support full UTF-8 (emojis, asian symbols, mathematical symbols) applied gives us some test failures as utf8mb4 support requires schema updates. Just wondering how we'd best deal with this?