Problem/Motivation

\Drupal\Tests\system\Functional\Module\VersionTest can do with some modernisation, it makes 14 http requests to validate version constraints

Proposed resolution

Retain one functional test for the disabled checkboxes
Move the rest to a kernel or possibly unit test

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3050353

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

larowlan created an issue. See original summary.

claudiu.cristea’s picture

larowlan’s picture

Note we could move the bulk of these into \Drupal\Tests\Component\Version\ConstraintTest::providerIsCompatible

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mstrelan made their first commit to this issue’s fork.

mstrelan’s picture

Status: Active » Needs review

This was originally added 11 years ago in #211747: Allow specifying version information as part of module dependencies. I approached this first by doing the least possible to convert from a Functional test to a Kernel test.

Before
Time: 00:44.311, Memory: 12.00 MB

After:
Time: 00:00.909, Memory: 12.00 MB

Before refactoring further I wonder if it's worth just committing this for the massive speed boost and then discussing the following.

I think started investigating how it works and wish I had never seen this. The test has an array of dependency strings. Every odd numbered dependency is valid and every even numbered dependency is invalid. This is stored in state. There is a hook \Drupal\system_test\Hook\SystemTestHooks::systemInfoAlter that shifts the first constraint off the list and alters the info for the module_test module. The test then loops through the dependency strings, loads the modules form which invokes the hook, and checks if the checkbox to enable module_test is disabled or not.

So I began to wonder what it is we're actually trying to test. Is this the syntax of the version strings? Is it that the checkbox is disabled for incompatible modules? In #3 @larowlan mentioned we could probably just add most of these to \Drupal\Tests\Component\Version\ConstraintTest::providerIsCompatible. But when I stepped through the code it seems it might be more appropriate to expand \Drupal\Tests\Core\Extension\DependencyTest::testIsCompatible. The test essentially boils down to the value of $incompatible in this snippet:

// If this module requires other modules, add them to the array.
/** @var \Drupal\Core\Extension\Dependency $dependency_object */
foreach ($module->requires as $dependency => $dependency_object) {
  // @todo Add logic for not displaying hidden modules in
  //   https://drupal.org/node/3117829.
  if ($incompatible = $this->checkDependencyMessage($modules, $dependency, $dependency_object)) {
mstrelan’s picture

I also tried using a provider but it's quite a lot slower:

Time: 00:08.720, Memory: 12.00 MB

So I've reverted that, but made some tweaks to remove some hacks like the static variable and the array_shift. It means state is only set in the test and not also in the hook, which makes it easier to understand the even/odd logic.

mstrelan’s picture

Component: base system » system.module
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a good refactor to me. Still asserting that things are disabled as before. See no issue.

  • catch committed 222d7506 on 11.x
    Issue #3050353 by mstrelan, larowlan: \Drupal\Tests\system\Functional\...
catch’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

This was originally added 11 years ago in #211747: Allow specifying version information as part of module dependencies.

Had a quick look at the issue, I think it was actually added 16 years ago? Looks like the cvs commit happened in 2009.

Let's definitely open a follow-up to discuss whether we should remove the test altogether or if it can be simplified further.

Committed/pushed to 11.x, thanks!

mstrelan’s picture

You're right, it was 16 years ago, it was the last updated date on the issue that was 11 years ago.

Follow up #3538668: Decide the fate of Drupal\Tests\system\Kernel\Module\ModulesListFormTest

Status: Fixed » Closed (fixed)

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