Problem/Motivation
There are tests that use the state service to determine whether a value was set as expected. Many of these usages are not testing the state service specifically, such as in #3477586: [random test failure] LayoutBuilderBlocksTest::testBlockPlaceholder failing . There are race conditions associated with state that can cause intermittent test failures. While the race conditions are being addressed in #3496257: Race conditions in CacheCollector/State (again), using state in this cases should be replaced using key value storage directly.
This issue is to identify all the instances of stage usage that can be replaced. If the number of instances is small, then likely replacing them can all be done here as well. Or perhaps this issue can be converted to a meta with separate child issues to replace individual instances to break the work up.
Comments
Comment #2
quietone commentedComment #3
catchEntityComputedFieldTest has a random failure that looks like it's due to state usage:
https://git.drupalcode.org/project/drupal/-/jobs/5355698
Comment #5
catchUpdating the issue title, we unless we're actually testing the state system we shouldn't be using it in test modules etc.
Comment #6
joachim commentedWhat??
State is a really useful way for Kernel tests to set things for fixture code to pick up. The entity_test module uses it LOADS:
Comment #7
catch@joachim, see the issue title:
Also #3496257: Race conditions in CacheCollector/State (again).
Comment #8
joachim commentedI saw. I'm saying this is going to have a massive impact across tests -- lots of contrib tests will be using those test entity types too. And that it's a bit ridiculous that state is broken like this.
And how is it going to be enforced / documented not to use state in tests for passing/stashing information?
Comment #9
catch#3496257: Race conditions in CacheCollector/State (again) has an MR that needs review.
It won't be enforced, some tests need to test the actual state system. Core can lead by example though. I don't see how updating some tests is worse than the tests failing randomly.
Comment #10
godotislateSince #3502432: Make hook testing with kernel tests very simple and #3390193: Add a drupalGet() method to KernelTestBase, there are probably a bunch of tests where we can eliminate the use of storing things in state/keyvalue at all. Hook implementations that live inside the Kernel test class can have properties that are set and checked, instead of stored values in the database. And moving some functional tests to kernel tests might make those tests eligible for the same treatment.