From 5b07dc1bdec0bde2475d5e786f43c98bcd185f8e Mon Sep 17 00:00:00 2001 From: catch Date: Thu, 29 Apr 2021 17:22:35 +0100 Subject: [PATCH] Revert "Issue #3211164 by alexpott: Random errors in Javascript Testing" This reverts commit 15d5418f8a9f8d3fc5aba1a56db2c652208e2653. --- .../WebDriverCurlService.php | 27 ++----------------- .../WebDriverTestBase.php | 16 ----------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php index 32bba6d44d5..eb2eb301f36 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverCurlService.php @@ -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)); } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php index 2478b5e28d1..6f1bc12db4f 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php @@ -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))');