Problem/Motivation
While working on resolving the remaining test failures in #2429617-75: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!), I noticed that TrustedHostsTest has a failure. Specifically, in this test:
protected function setUp() {
//…
$this->drupalLogin($admin_user);
}
public function testShortcut() {
$this->container->get('module_installer')->install(['block', 'shortcut']);
$this->rebuildContainer();
//…
$this->drupalPlaceBlock('shortcuts');
$this->drupalGet('');
$this->assertLink($shortcut->label());
}
What happens here, is that we first log in, which causes a SmartCache cache item to be created. But that cache item is never invalidated, even though the Block module will select a different page display variant!
Proposed resolution
Because block module implements a custom page display variant, *and* it does not require any configuration to take over page rendering, it should invalidate the 'rendered' cache tag, to ensure all cached output is invalidated.
Remaining tasks
Do it.
User interface changes
None.
API changes
None.
Comments
Comment #1
wim leersComment #2
fabianx commentedRTBC - if tests pass
Comment #5
fabianx commentedTest fluke
Comment #6
xjmPlease, when you click retest, document what the test failure was. :)
Comment #7
xjmThanks @Fabianx and @Wim Leers. The change makes sense. Yay for fewer cache invalidation bugs! However, I think we should probably add test coverage that the cache is invalidated? I see that #242961: Download system? would add test coverage (per the summary), but best to add a focused test with this fix, I think.
Comment #8
wim leersI honestly don't see the value of adding test coverage for this. It is a single hook implementation, and that implementation does a single function call. Both the hook being invoked and the function call's consequences are thoroughly tested. This would therefore then only be testing that this single function call is being invoked. But we know that it is being invoked.
Here, the cost of writing test coverage outweighs the benefits, IMHO.
Back to RTBC for more committer feedback.
Comment #9
catchhook_modules_installed() runs when any module is installed.
This should either be in hook_install() or at least check that block is in the list no?
Comment #10
wim leersClearly I'm an idiot, because I even managed to get this trivial patch wrong. Which completely undermines my arguments in #8. In other words: I've made a fool of myself :)
Here's a fixed patch, with test coverage.
Comment #12
berdirThat looks better :)
Comment #14
catchSo the test is fine to make sure the hook_install() works, but it wouldn't test for the issue in #10 where this happens on any module install rather than just block. However testing that the cache isn't invalidated when another module is installed definitely would be too much testing overhead.
Committed/pushed to 8.0.x, thanks!
Comment #16
jibranWhy is the install hook in
.modulefile and not in.installfile?Comment #17
jibranCreated #2535284: Move block_install hook to block.install file.
Comment #18
effulgentsia commentedBlock module is not the only module that influences what is rendered. Quickedit, RDF, and many other modules do as well. Therefore: #2783791: Module install doesn't invalidate render cache.