Revert "Issue #3211164 by alexpott: Random errors in Javascript Testing"

This reverts commit 15d5418f8a.
merge-requests/660/head
catch 2021-04-29 17:22:35 +01:00
parent 15d5418f8a
commit 5b07dc1bde
2 changed files with 2 additions and 41 deletions

View File

@ -14,25 +14,6 @@ use WebDriver\Exception as WebDriverException;
*/
class WebDriverCurlService extends CurlService {
/**
* The maximum number of times to try in the event of a stale element
* reference error.
*
* @var int
*/
private static $maxRetries = 10;
/**
* Sets the maximum number of retries.
*
* @param int $max_retries
* The maximum number of times to try in the event of a stale element
* reference error. This number must be greater than 10.
*/
public static function setMaxRetries(int $max_retries) {
static::$maxRetries = max($max_retries, static::$maxRetries);
}
/**
* {@inheritdoc}
*/
@ -41,7 +22,7 @@ class WebDriverCurlService extends CurlService {
CURLOPT_FAILONERROR => TRUE,
];
$retries = 0;
while ($retries < static::$maxRetries) {
while ($retries < 10) {
try {
$customHeaders = [
'Content-Type: application/json;charset=UTF-8',
@ -123,9 +104,8 @@ class WebDriverCurlService extends CurlService {
$result = json_decode($rawResult, TRUE);
if (isset($result['status']) && $result['status'] === WebDriverException::STALE_ELEMENT_REFERENCE) {
usleep(100000);
$retries++;
// Wait a bit longer each time a stale reference error has occurred.
usleep(100000 * $retries);
continue;
}
return [$rawResult, $info];
@ -134,9 +114,6 @@ class WebDriverCurlService extends CurlService {
$retries++;
}
}
if (empty($error)) {
$error = "Retries: $retries and last result:\n" . ($rawResult ?? '');
}
throw WebDriverException::factory(WebDriverException::CURL_EXEC, sprintf("Curl error thrown for http %s to %s%s\n\n%s", $requestMethod, $url, $parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '', $error));
}

View File

@ -4,7 +4,6 @@ namespace Drupal\FunctionalJavascriptTests;
use Behat\Mink\Exception\DriverException;
use Drupal\Tests\BrowserTestBase;
use PHPUnit\Runner\BaseTestRunner;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Zumba\GastonJS\Exception\DeadClient;
use Zumba\Mink\Driver\PhantomJSDriver;
@ -35,22 +34,12 @@ abstract class WebDriverTestBase extends BrowserTestBase {
*/
protected $minkDefaultDriverClass = DrupalSelenium2Driver::class;
/**
* The maximum number of times to try a webdriver request.
*
* @var int
*
* @see \Drupal\FunctionalJavascriptTests\WebDriverCurlService::$maxRetries
*/
protected const WEBDRIVER_RETRIES = 10;
/**
* {@inheritdoc}
*/
protected function initMink() {
if ($this->minkDefaultDriverClass === DrupalSelenium2Driver::class) {
$this->minkDefaultDriverArgs = ['chrome', NULL, 'http://localhost:4444'];
WebDriverCurlService::setMaxRetries(max((int) getenv('WEBDRIVER_RETRIES'), static::WEBDRIVER_RETRIES));
}
elseif ($this->minkDefaultDriverClass === PhantomJSDriver::class) {
// Set up the template cache used by the PhantomJS mink driver.
@ -109,11 +98,6 @@ abstract class WebDriverTestBase extends BrowserTestBase {
*/
protected function tearDown() {
if ($this->mink) {
$status = $this->getStatus();
if ($status === BaseTestRunner::STATUS_ERROR || $status === BaseTestRunner::STATUS_WARNING || $status === BaseTestRunner::STATUS_FAILURE) {
// Ensure we capture the output at point of failure.
@$this->htmlOutput();
}
// Wait for all requests to finish. It is possible that an AJAX request is
// still on-going.
$result = $this->getSession()->wait(5000, '(typeof(jQuery)=="undefined" || (0 === jQuery.active && 0 === jQuery(\':animated\').length))');