Skip to content

Commit

Permalink
Measure snooze time.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jan 30, 2024
1 parent ddb1a3f commit a6b7e19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion module/VuFind/src/VuFindTest/Feature/AutocompleteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ trait AutocompleteTrait
public function getAndAssertFirstAutocompleteValue(Element $page, string $text): Element
{
$tries = 0;
$snoozeTime = 0;
$loadMsg = 'Loading…';
do {
$acItem = $this->findCss($page, '.autocomplete-results .ac-item');
$acItemText = $acItem->getText();
if (strcasecmp($acItemText, $loadMsg) === 0) {
$this->snooze(0.5);
$snoozeTime += 0.5 * $this->getSnoozeMultiplier();
}
$tries++;
} while (strcasecmp($acItemText, $loadMsg) === 0 && $tries <= 5);
$this->assertEquals(
$text,
$this->findCss($page, '.autocomplete-results .ac-item')->getText(),
"Failed after $tries tries."
"Failed after $tries tries, with $snoozeTime seconds snooze time."
);
return $acItem;
}
Expand Down
12 changes: 11 additions & 1 deletion module/VuFind/src/VuFindTest/Integration/MinkTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,23 @@ protected function changeYamlConfigFile($configName, $settings, $replace = false
*/
protected function snooze($secs = 1)
{
$snoozeMultiplier = floatval(getenv('VUFIND_SNOOZE_MULTIPLIER'));
$snoozeMultiplier = $this->getSnoozeMultiplier();
if ($snoozeMultiplier <= 0) {
$snoozeMultiplier = 1;
}
usleep(1000000 * $secs * $snoozeMultiplier);
}

/**
* Get the snooze multiplier.
*
* @return float
*/
protected function getSnoozeMultiplier(): float
{
return floatval(getenv('VUFIND_SNOOZE_MULTIPLIER'));
}

/**
* Get the default timeout in milliseconds
*
Expand Down

0 comments on commit a6b7e19

Please sign in to comment.