ItemCacheTagsTest and ShortcutCacheTagsTest needlessly test the render cache.

Created on 3 October 2019, over 5 years ago
Updated 13 January 2025, about 2 months ago

ItemCacheTagsTest::testEntityCreation() and ShortcutCacheTagsTest::testEntityCreation() check for cache entries in the render cache even though nothing was cached. This needlessly complicates things as any refactoring of the render cache might inadvertently make these tests fail as shown in #2551419-158: Abstract RenderCache into a separate service that is capable of cache redirects in a non-render array-specific way

The easy fix is to add a new method to the base class that allows you to run a slimmed down version of verifyRenderCache that only runs the basic checks, does not check for redirects and, most importantly, uses the default cache backend.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

system.module

Created by

🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • First commit to issue fork.
  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Rerolled patch from #14

  • Pipeline finished with Success
    about 2 months ago
    Total: 591s
    #395985
  • 🇺🇸United States smustgrave

    ItemCacheTagsTest was removed with aggregator so title doesn't need it

    Left a comment on MR.

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Trying to get feedback.

  • 🇺🇸United States smustgrave

    Think my one comment still stands but will leave in review for others. Certainly not a hill I’ll die on lol

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Haha, I’m with you on being efficient and avoiding unnecessary duplication of resources.

    We could refactor EntityCacheTagsTestBase so that the cache bins are stored in a class member variable within the setUp() method, which is a common practice. However, I always try to be cautious about not straying too far from the original scope.

    You have a lot of experience, so I’m always a bit worried about overlooking something.

    Let’s see if others can share their thoughts, and we’ll decide from there. :)

    Thanks so much for all the effort you put into reviewing so many (often complex) issue queues!

  • 🇺🇸United States smustgrave

    Been some time without additional feedback. Since the one open thread was my own going to mark and see what a committer things. Since this is tests optimization I'm not as picky with the thread so it could be ignored.

  • 🇬🇧United Kingdom catch

    This method doesn't do any http requests, so I think it could move to a kernel test?

  • Pipeline finished with Failed
    13 days ago
    Total: 136s
    #430877
  • Pipeline finished with Failed
    13 days ago
    Total: 609s
    #430887
  • Pipeline finished with Failed
    13 days ago
    Total: 136s
    #430903
  • Pipeline finished with Success
    13 days ago
    Total: 607s
    #430904
  • 🇪🇸Spain vidorado Logroño (La Rioja)

    I hadn't realized that! Good idea! 🙂

    I've implemented it and also extracted some common functionality into a trait.

  • 🇺🇸United States smustgrave

    Not sure if I missed it the first time but looking at the summary doesn't mention adding a new trait. Think if that's going to be an approach IS should be updated and a CR written.

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Thanks for your review @smustgrave!

    Using a trait wasn’t the initial decision, but after @catch’s suggestion to move Functional/ShortcutCacheTagsTest::testEntityCreation() to a kernel test, it was no longer possible to reuse the functions through inheritance. As a result, they were moved into a trait.

    I've updated the proposed solution in the IS to reflect this.

    I don't think a CR would be necessary since EntityCacheTagsTestBase, which originally contained these methods, now uses the trait, meaning any subclass will automatically inherit them. Additionally, since these functions were not static, a static call like EntityCacheTagsTestBase::getRenderCacheBackend() would never have existed anywhere.

  • 🇺🇸United States smustgrave

    Will leave for others then. But if we don’t want to declare a new trait then not sure I see the point of doing it..

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Traits can be a bit tricky, as they were introduced to solve the multiple inheritance problem.

    I found this article quite interesting when I read it some time ago: PHP Traits: If They Weren’t Evil, They’d Be Funny.

    If we consider traits as an "official" tool for developers to use across multiple tests, then you're probably right about the need for a CR. However, in this case, the trait is simply a way to reuse code without overcomplicating things.

    Would it have been better to implement this with composition using a service or something similar? Or is a trait a bigger architectural change that warrants a CR to properly inform developers about this new tool?

    These are still open questions for me, given my yet limited experience with the core codebase. 🙂

  • 🇬🇧United Kingdom catch

    If we added a new trait to the runtime codebase it might warrant a CR, but a trait just to share logic across a couple of tests does not need a change record, for the same reason test code in general is considered @internal per https://www.drupal.org/about/core/policies/core-change-policies/bc-polic...

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Thanks for your input, @catch. Sometimes the boundaries are unclear, and I find it valuable to hear multiple perspectives and learn from them for future situations.

  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    The MR seems close to what I originally had in mind. Only not fond of the naming. The trait might imply that it also works for regular caches, but that's not the case as it's heavily oriented towards variation caches.

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Thanks for your suggestion, @kristiaanvandeneynde!

    After reviewing it more thoroughly, I'm not entirely sure about the need for "Variation" in the method name. Perhaps "Variation" is an implementation detail, there isn’t another method that directly returns a CacheBackendInterface, and more importantly, the method is type-hinted.

    However, I've made the change for others to review. 🙂

  • Pipeline finished with Success
    10 days ago
    Total: 354s
    #432785
  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    Yeah it was merely a suggestion. I'm fine to review either way you want to change it, but I do think we should try to make it so our trait and method names cannot be considered ambiguous.

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Yes, yes, I totally agree! I'm very concerned about naming, I always take my time to make sure I choose the best possible name. It's just that this time, I'm not entirely sure because of the questions I mentioned :)

  • Pipeline finished with Success
    10 days ago
    Total: 670s
    #432809
  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    Hmm, now EntityCacheTagsTestBase loses the getRenderCacheBackend() method and gets getRenderVariationCacheBackend() in return. This could upset people extending said base class.

    Then again, the previous name was incorrect now that it was returning a VariationCacheInterface, which is not a backend, but a wrapper around a backend. I need to fix VariationCacheFactoryInterface in that regard.

    So, with my sincerest apologies, could we have one more round of changes please?

    • getDefaultVariationCacheBackend() -> getDefaultVariationCache()
    • getRenderVariationCacheBackend() -> getRenderVariationCache()

    Then the names match what they are actually retrieving.

    From the BC policy:

    Test traits and abstract base classes should generally use deprecation where possible rather than breaking backwards compatibility, but they are still considered an internal API and may change if necessary.

    So on the base class we should have the old method (getRenderCacheBackend) call the new method (getRenderVariationCache) along with a deprecation notice.

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    No worries! The search for a good and elegant solution often requires a few iterations. 🙂

    I think I searched for other uses of EntityCacheTagsTestBase::getRenderCacheBackend() and couldn't find any, but I overlooked the possibility that contrib modules might be extending this class as well, so I think it's a good idea to keep the method and deprecate it.

    I've fixed the naming as you suggested, restored the getRenderCacheBackend() method, deprecated it, and created a CR.

    Thanks for the detailed information you provided!

    Let me know if I've forgotten something.

  • Pipeline finished with Success
    9 days ago
    Total: 1679s
    #433669
  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    Amazing work, got nothing left to say.

    • catch committed c29d83bc on 11.x
      Issue #3085475 by vidorado, Ankit.Gupta, kristiaanvandeneynde,...
  • 🇬🇧United Kingdom catch

    Edit: I wonder if test classes are considered @internal, meaning a CR and deprecation wouldn’t be strictly necessary. However, doing so is certainly the more considerate approach.

    fwiw this is exactly how we approach it most of the time, if we really need to skip deprecating and introduce a hard break then we can and will, but if it's straightforward to provide bc then that's preferred to avoid disrupting contrib modules too much/often in minor releases.

    Committed/pushed to 11.x, thanks!

  • 🇪🇸Spain vidorado Logroño (La Rioja)

    Thanks for clarifying this, @catch 😊

Production build 0.71.5 2024