EntityCacheTagsTestBase doesn't allow a module to interact with page tags and test entity cache tags at the same time

Created on 29 October 2019, about 5 years ago
Updated 29 February 2024, 9 months ago

Problem/Motivation

While investigating #2914110 I came to the realization that EntityCacheTagsTestBase::testReferencedEntity() is very complicated and sort of breaks shortcuts ability to use the class for its test.

There is a lot going on in this test. Cache::mergeContexts for days but you don't really need to understand those if we look very closely at the code failing for shortcut.module to get to the root of the problem.

$this->verifyPageCache($referencing_entity_url, 'HIT', $expected_tags);

Two pieces of context, first $referencing_entity_url = $this->referencingEntity->toUrl('canonical');
Additional $this->referencingEntity is a \Drupal\entity_test\Entity\EntityTest that in setUp dynamically creates a reference and stores a reference the entity being tested. In this case a shortcut entity.

So now the assertion, verifyPageCache(), makes a request to the canonical url and checks the cache tags on the full page render. It seems the logic being tested is that the tags from the reference entity are bubbled up as part of the entity and those should bubble all the way to the full page. Kinda ugly but you can sort of follow it.

The complexity of testing the _entire_ render process instead of just the entity cache tag reference logic directly is what's causing the problem though. By varying the cache tags through the page_title on every page we're changing the base cache tags for every page. That breaks this assertion(and dozens of later assertions) because the test can't handle that and assumes all pages will have the same base set of tags. Any interaction with that from a module breaks the test.

Proposed resolution

?

Remaining tasks

?

User interface changes

n/a

API changes

?

Data model changes

n/a

Release notes snippet

?

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States neclimdul Houston, TX

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Just rediscovered these tests and the 2-3 base classes. I think we could remove the page cache stuff, and make them kernel tests for a start?

Production build 0.71.5 2024