Problem/Motivation

Per @alexpott in #3278493-112: Make it easier for theme builders to enable Twig debugging and disable render cache:

I wish we'd added a bigger comment in #3358048: Do not use persist tag for keyvalue.memory in KernelTestBase

When I reviewed #3358048 it all seemed pretty clear and self-documenting to me. But it's a very important change and a somewhat tricky part of Drupal (Kernel tests are always a bit weird). So probably we should be a bit more verbose.

Steps to reproduce

Proposed resolution

Flesh out the docs on both the $keyValue protected member itself, and the spot we manipulate it in ::register().

Remaining tasks

  1. Decide what more to say.
  2. Update the comments.

User interface changes

API changes

Data model changes

Release notes snippet

Comments

dww created an issue. See original summary.

mglaman’s picture

Words:

We cannot trust the container to persist properly, which we have found buggy. If the service doesn't persist, then data is lost. Instead of requiring all kernel tests to install the key_value schema, we use the storage backend and manually replace it to persist state.

Which if `persist` tag is removed, maybe we need better words. Or we use that wording and update the "remove persist tag" to include adjusting this comment.

alexpott’s picture

Status: Active » Needs review
StatusFileSize
new1.98 KB

I think we shoudl move things about a bit - and make the kernel test environment a bit more real. There's no reason to add a keyvalue.memory service and use aliases as far as I can - it's all unnecessary redirection. Also the comment should be less about persistence and more about why we're even bothering doing this.

mglaman’s picture

This makes sense. Swapping the definition and being more direct. +1 from me.

My only stylistic nits would be that I prefer explicit null checks

if (!isset($this->keyValue)) {

That's it! Otherwise RTBC to me (pending test results)

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Moving to RTBC per #4. Will let the committer decide to make that small change mentioned (didn't seem like a blocker).

dww’s picture

Title: Add a bigger comment to KernelTestBase about keyValue and persistence » Improve how KernelTestBase manages its persistent key value storage
Priority: Minor » Normal

Yay, this is cleaner still, and involves even less magic / indirection / obfuscation. +1 to #3.

Here's a more accurate title for the scope of this issue. Also, since it's no longer just adding more verbose docs, bumping priority a bit.

I'm also not NW'ing for #4, but would be happy to upload a new patch if committers prefer === NULL vs. !isset().

alexpott’s picture

Fwiw isset() is more accurate that the NULL check and does not access the value so the difference becomes very important for read only values. The type of the variable does not actually allow for NULL values.

mglaman’s picture

Thanks @alexpott. ignore me in #4. I forgot it was a typed property where you need to use isset.

alexpott’s picture

I've checked that tests like https://git.drupalcode.org/project/pathauto/-/blob/8.x-1.x/tests/src/Ker... continue to use a database. Not sure why that test makes the change it does but it still works - and I've checked that it is actually using the database (FWIW it passes when using the memory storage too). Here's the search I did to ensure that removing the keyvalue.memory service from KTB is safe - https://git.drupalcode.org/search?group_id=2&repository_ref=&scope=blobs...

  • catch committed 55aead3d on 10.0.x
    Issue #3358328 by alexpott, dww, mglaman: Improve how KernelTestBase...

  • catch committed b6aef35b on 10.1.x
    Issue #3358328 by alexpott, dww, mglaman: Improve how KernelTestBase...

  • catch committed 681046af on 9.5.x
    Issue #3358328 by alexpott, dww, mglaman: Improve how KernelTestBase...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!

andypost’s picture

Status: Fixed » Needs work

backport to 9.5 needs revert and new patch without type for property https://www.drupal.org/pift-ci-job/2663367

  • alexpott committed 84a8f0ee on 9.5.x
    Issue #3358328 followup by andypost: Improve how KernelTestBase manages...
andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new532 bytes
new1.71 KB

Valid patch, interdiff vs #3

andypost’s picture

Status: Needs review » Fixed

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.