Verified Commit 46ed71cf authored by Dave Long's avatar Dave Long
Browse files

Issue #3420401 by alexpott, catch, Spokje, smustgrave, quietone, longwave:...

Issue #3420401 by alexpott, catch, Spokje, smustgrave, quietone, longwave: StandardPerformanceTest fails randomly on MySQL and consistently on Postgres
parent 89fde7a6
Loading
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public function testAnonymous() {
      $this->drupalGet('');
    }, 'standardFrontPage');
    $this->assertNoJavaScript($performance_data);
    $this->assertSame(68, $performance_data->getQueryCount());
    $this->assertCountBetween(68, 69, $performance_data->getQueryCount());
    $this->assertSame(137, $performance_data->getCacheGetCount());
    $this->assertSame(47, $performance_data->getCacheSetCount());
    $this->assertSame(0, $performance_data->getCacheDeleteCount());
@@ -105,8 +105,7 @@ public function testLogin(): void {
      $this->submitLoginForm($account);
    });

    $this->assertGreaterThanOrEqual(38, $performance_data->getQueryCount());
    $this->assertLessThanOrEqual(40, $performance_data->getQueryCount());
    $this->assertCountBetween(38, 43, $performance_data->getQueryCount());
    $this->assertSame(64, $performance_data->getCacheGetCount());
    $this->assertSame(1, $performance_data->getCacheSetCount());
    $this->assertSame(1, $performance_data->getCacheDeleteCount());
@@ -136,7 +135,7 @@ public function testLoginBlock(): void {
    $performance_data = $this->collectPerformanceData(function () use ($account) {
      $this->submitLoginForm($account);
    });
    $this->assertSame(49, $performance_data->getQueryCount());
    $this->assertCountBetween(49, 52, $performance_data->getQueryCount());
    $this->assertSame(85, $performance_data->getCacheGetCount());
    $this->assertSame(1, $performance_data->getCacheSetCount());
    $this->assertSame(1, $performance_data->getCacheDeleteCount());
+14 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\FunctionalJavascriptTests;

use Drupal\Core\Database\Database;
use Drupal\Tests\PerformanceTestTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

@@ -28,6 +29,19 @@ protected function setUp(): void {
    $this->doSetUpTasks();
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $db = Database::getConnection();
    $test_file_name = (new \ReflectionClass($this))->getFileName();
    $is_core_test = str_starts_with($test_file_name, DRUPAL_ROOT . DIRECTORY_SEPARATOR . 'core');
    if ($db->databaseType() !== 'mysql' && $is_core_test) {
      $this->markTestSkipped('Drupal core performance tests only run on MySQL');
    }
  }

  /**
   * {@inheritdoc}
   */
+22 −0
Original line number Diff line number Diff line
@@ -407,4 +407,26 @@ private function openTelemetryTracing(array $messages, string $service_name): vo
    }
  }

  /**
   * Asserts that a count is between a min and max inclusively.
   *
   * @param int $min
   *   Minimum value.
   * @param int $max
   *   Maximum value.
   * @param int $actual
   *   The number to assert against.
   *
   * @return void
   *
   * @throws \PHPUnit\Framework\ExpectationFailedException
   */
  protected function assertCountBetween(int $min, int $max, int $actual) {
    static::assertThat(
      $actual,
      static::logicalAnd(static::greaterThanOrEqual($min), static::lessThanOrEqual($max)),
      "$actual is greater or equal to $min and is smaller or equal to $max",
    );
  }

}