mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-66979 behat: Add a step to set a timeout factor for a test
This commit is contained in:
parent
adc8204a83
commit
bead2a1d96
3 changed files with 33 additions and 7 deletions
|
@ -1355,4 +1355,25 @@ EOF;
|
||||||
|
|
||||||
return $this->evaluate_script($script);
|
return $this->evaluate_script($script);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the timeout factor for the remaining lifetime of the session.
|
||||||
|
*
|
||||||
|
* @param int $factor A multiplication factor to use when calculating the timeout
|
||||||
|
*/
|
||||||
|
public function set_test_timeout_factor(int $factor = 1): void {
|
||||||
|
$driver = $this->getSession()->getDriver();
|
||||||
|
|
||||||
|
if (!$driver instanceof \OAndreyev\Mink\Driver\WebDriver) {
|
||||||
|
// This is a feature of the OAndreyev MinkWebDriver.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use `get_real_timeout` to multiply the timeout by the global behat_increasetimeout value, and again by the
|
||||||
|
// factor specified.
|
||||||
|
$this->getSession()->getDriver()->setTimeouts([
|
||||||
|
// The standard script timeout is 30000 ms. (aka, 30 seconds).
|
||||||
|
'script' => self::get_real_timeout(30) * 1000 * $factor,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2065,4 +2065,15 @@ EOF;
|
||||||
$localurl = new moodle_url($localurl);
|
$localurl = new moodle_url($localurl);
|
||||||
$this->getSession()->visit($this->locate_path($localurl->out_as_local_url(false)));
|
$this->getSession()->visit($this->locate_path($localurl->out_as_local_url(false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase the webdriver timeouts.
|
||||||
|
*
|
||||||
|
* This should be reset between scenarios, or can be called again to decrease the timeouts.
|
||||||
|
*
|
||||||
|
* @Given I mark this test as slow setting a timeout factor of :factor
|
||||||
|
*/
|
||||||
|
public function i_mark_this_test_as_long_running(int $factor = 2): void {
|
||||||
|
$this->set_test_timeout_factor($factor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,13 +303,7 @@ EOF;
|
||||||
protected function start_session(): void {
|
protected function start_session(): void {
|
||||||
$this->getSession()->start();
|
$this->getSession()->start();
|
||||||
|
|
||||||
if ($this->running_javascript()) { // Goutte driver doesn't implement this.
|
$this->set_test_timeout_factor(1);
|
||||||
$this->getSession()->getDriver()->setTimeouts([
|
|
||||||
// The standard script timeout is 30000 ms. (aka, 30 seconds).
|
|
||||||
// Use `get_real_timeout` to multiply this by the behat increased timeout factor.
|
|
||||||
'script' => self::get_real_timeout(30) * 1000,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue