Reset static entity cache on POST requests in tests

Created on 17 March 2019, almost 6 years ago
Updated 6 November 2024, about 2 months ago

Problem/Motivation

We already reset quite a few things when doing POST requests, like statically cached config. We didn't do it for entities because we didn't have an API for that for a long time.

Doing this should remove the need for a lot of manual cache clear calls.

Proposed resolution

Reset the static entity cache service.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component

simpletest.module

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
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.

  • @berdir opened merge request.
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Beside removing a lot of complexity (when and when not to reset cache) and lines of code, it also uncovers bugs and incorrect assumptions in tests when we forget to reset the cache.

    For example https://git.drupalcode.org/project/drupal/-/merge_requests/10075/diffs?c.... That test never actually tested what I thought it did, because it was always testing against the original stale entity.

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    1) Drupal\Tests\block\Functional\BlockCacheTest::testCachePermissions
    Behat\Mink\Exception\ResponseTextException: The text "smx906fw" was not
    found anywhere in the text of the current page.

    Appears to be random but since 100+ commits back now I did a simple rebase to make sure.

    I wasn't 100% sure if we should have a CR but since it's just around tests I didn't think it would be needed.

    Edit

    Rebase was good and green.

    Change LGTM

  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    I'm not sure if there is a policy that speaks to this but a CR would be good as this is a pretty important change to the base test setup and is not obvious.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Lets do it!

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Created https://www.drupal.org/node/3491185 β†’ .

    This is mostly a DX thing when writing new tests and shouldn't affect any existing tests, except those that implicitly or explicitly rely on the current static cache behavior, like the one example in core that I had to fix.

    For new tests, it should now mostly just work without having to think about internal entity features.

    Note: I have not verified if every single resetCache() call in core is still needed, but I removed enough to show that this works I think and quite a few are still necessary as their changes are not done by form submissions.

Production build 0.71.5 2024