Skip to content

Commit

Permalink
MDL-70014 tool_customlang: Workaround to make behat happier
Browse files Browse the repository at this point in the history
This is a BEHAT_RUNNING only hack, so it doesn't affect normal
operations at all. What it achieves is to reduce the number of
strings loaded when customising a lang pack from current 31K ones
to the just needed ones for Behat testing purposes.

That way we avoid the random failures that are happening more and
more (while the "en" lang pack grows) and also save some precious
minutes in every behat run.

Also, unrelated, a couple of tiny changes:
- Modified constant (that was really outdated) to current number
  of lang strings (so the progress bar behaves better).
- Remove an elseif occurrence because it was hurting my eyes.
  • Loading branch information
stronk7 committed Apr 1, 2022
1 parent 6e7c7a7 commit 55198f8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions admin/tool/customlang/locallib.php
Expand Up @@ -36,7 +36,7 @@ class tool_customlang_utils {
* Rough number of strings that are being processed during a full checkout.
* This is used to estimate the progress of the checkout.
*/
const ROUGH_NUMBER_OF_STRINGS = 16500;
const ROUGH_NUMBER_OF_STRINGS = 32000;

/** @var array cache of {@link self::list_components()} results */
private static $components = null;
Expand Down Expand Up @@ -91,9 +91,22 @@ public static function list_components() {
public static function checkout($lang, progress_bar $progressbar = null) {
global $DB;

// For behat executions we are going to load only a few components in the
// language customisation structures. Using the whole "en" langpack is
// too much slow (leads to Selenium 30s timeouts, especially on slow
// environments) and we don't really need the whole thing for tests. So,
// apart from escaping from the timeouts, we are also saving some good minutes
// in tests. See MDL-70014 and linked issues for more info.
$behatneeded = ['core', 'core_langconfig', 'tool_customlang'];

// make sure that all components are registered
$current = $DB->get_records('tool_customlang_components', null, 'name', 'name,version,id');
foreach (self::list_components() as $component) {
// Filter out unwanted components when running behat.
if (defined('BEHAT_SITE_RUNNING') && !in_array($component, $behatneeded)) {
continue;
}

if (empty($current[$component])) {
$record = new stdclass();
$record->name = $component;
Expand All @@ -103,7 +116,7 @@ public static function checkout($lang, progress_bar $progressbar = null) {
$record->version = $version;
}
$DB->insert_record('tool_customlang_components', $record);
} elseif ($version = get_component_version($component)) {
} else if ($version = get_component_version($component)) {
if (is_null($current[$component]->version) or ($version > $current[$component]->version)) {
$DB->set_field('tool_customlang_components', 'version', $version, array('id' => $current[$component]->id));
}
Expand Down

0 comments on commit 55198f8

Please sign in to comment.