Problem/Motivation

Found in #3644166: [META] Find and resolve external HTTP requests from core tests. The detector added there found 22 test classes contacting ftp.drupal.org through LocaleFileManager during the translation update batch, which runs at the end of a translated installation and when a language is added:

AssetOptimizationUmamiTest, ConfigTranslationInstallTest, DemoUmamiProfileTest, DistributionProfileTranslationQueryTest, DistributionProfileTranslationTest, DrupalFlushAllCachesInInstallerTest, HelpTopicTranslationTest, InstallerExistingConfigExistingSettingsTest, InstallerExistingConfigNoProfileTest, InstallerExistingConfigTest, InstallerLanguageDirectionTest, InstallerTranslationDownloadTest, InstallerTranslationMultipleLanguageKeepEnglishTest, InstallerTranslationQueryTest, InstallerTranslationTest, LocaleNonInteractiveInstallTest, LocaleThemeInstallTest, MultipleRequestsPerformanceTest, NodeTypeTranslationTest, OpenTelemetryPerformanceTest, UmamiMultilingualInstallTest, UninstallDefaultContentTest

The cause is that locale defaults to use_source: remote_and_local with the ftp.drupal.org server pattern, and most of the profiles these tests install keep that default: the testing and testing_locale test profiles even set it explicitly (while already disabling import_enabled "for automated tests"), the testing_config_install fixture does as well, and testing_multilingual_with_english, demo_umami and the profiles some tests generate on the fly do not configure locale at all. In main, these requests are HEAD requests whose result happens not to matter, because the local translation files the tests use are always newer. It still makes the tests depend on the network, and it already broke #3619842: Translation install and update batch does a HEAD and then a GET request for every project unnecessarily, does not accept compressed data, which turns the HEAD into a GET: ftp.drupal.org started serving the core 12.x German translation, which then got downloaded and imported, failing about 15 of these tests.

InstallerTranslationDownloadTest also has a related problem: it replaces the http_client service with a mock, but LocaleFileManager builds its own clients from http_client_factory, so those requests go past the mock to the real server.

Steps to reproduce

Run any of the tests above with the detector from #3644166: [META] Find and resolve external HTTP requests from core tests, or with ftp.drupal.org resolving to 127.0.0.1.

Proposed resolution

Tests that do not test remote translation updates should use local translation files only. Tests that do (like LocaleUpdateTest and LocaleTranslationChangeProjectVersionTest) already set translation.use_source explicitly and use the fake translation server of locale_test, so they are not affected.

  • Set use_source: local in the testing and testing_locale test profiles and the testing_config_install config fixture.
  • Add the same locale.settings as testing_multilingual to testing_multilingual_with_english.
  • Add LocalTranslationSourceTrait for browser tests installing a profile that does not configure locale (Umami, generated profiles): it adds a settings.php config override for locale.settings:translation.use_source before installation. Installer tests set the same override in $this->settings, like StandardRecipeInstallTest does for other config.
  • InstallerTranslationDownloadTest should replace http_client_factory with one using the same mock handler, and expect the HEAD request of the translation update batch for the custom profile.

I'm also adding the detector from #3644166: [META] Find and resolve external HTTP requests from core tests in a separate commit, to show that none of these tests make external requests anymore. That commit is not to be committed here and is only to show the fix works and the detector cannot detect those requests anymore.

Remaining tasks

Review.

Remove the detector commit before commit.

User interface changes

None.

Introduced terminology

None.

API changes

None. A new test trait, Drupal\Tests\locale\Traits\LocalTranslationSourceTrait.

Data model changes

None.

Release notes snippet

Not needed.

LLM disclosure

LLM was used to diagnose this problem and develop results. The results were reviewed and adjusted as a human though.

Issue fork drupal-3644177

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

gábor hojtsy created an issue. See original summary.

gábor hojtsy’s picture

gábor hojtsy’s picture

Status: Active » Needs review

With this fix 67 requests across 13 test jobs, down from 138 on #3644166: [META] Find and resolve external HTTP requests from core tests. None go to ftp.drupal.org or come from LocaleFileManager anymore :) So I think this achieves what we wanted. Question is if it can be done more elegantly. I pushed a bit of a cleanup to move the settings method on the trait too which should make it easier to add to later tests and also to grep for it.

gábor hojtsy’s picture

Issue tags: +Test suite performance