Problem/Motivation

Kernel tests force a memory backend for cache bins.

If we use the database cache and share the bins between methods, this can re-use discovery and other expensive to build cache items.

In local profiling, it's saving about 300ms or so from each method of NodeTypeValidationTest but also causes at least one test failure.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3629052

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

catch’s picture

Status: Active » Needs work

Works, but fails because it's working.

catch’s picture

Status: Needs work » Needs review

Resolved the test failures:

1. In KernelTestBase::enableModules() we need to clear the plugin caches to match ModuleInstaller::install() - this is because the caches can be populated before the ::enableModules() call which generally they wouldn't be in kernel tests before this change. There's a possibility there's some manual cache clears in existing tests that could be dropped but didn't look yet.

2. We need to exclude cache tables from the shared database state validation because they're ephemeral e.g. we allow those to be created and not cleaned up in a specific test method since they're created on-demand.

catch’s picture

catch’s picture

The plugin issue is making me wonder if we should forbid enabling a module during a test method when the environment is shared.

Tests that do this then have three options:

1. Add the module to static::$modules

2. Split the method(s) out to a separate test

(both of these will also be a performance improvement since it means less total container rebuilds)

3. Don't share the environment (can be combined with #2

plach’s picture

I agree, I reached the same conclusion here, see this commit.

catch’s picture

@plach could we move the check to ::tearDown() maybe? (or am I missing something and it would already cover all cases?). Also what do you think about splitting that out to its own issue?

plach’s picture

catch’s picture

Title: Share caches between kernel test methods » [PP-1] Share caches between kernel test methods
Status: Needs review » Postponed