Loading core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php +3 −4 Original line number Diff line number Diff line Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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()); Loading core/tests/Drupal/FunctionalJavascriptTests/PerformanceTestBase.php +14 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\FunctionalJavascriptTests; use Drupal\Core\Database\Database; use Drupal\Tests\PerformanceTestTrait; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -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} */ Loading core/tests/Drupal/Tests/PerformanceTestTrait.php +22 −0 Original line number Diff line number Diff line Loading @@ -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", ); } } Loading
core/profiles/standard/tests/src/FunctionalJavascript/StandardPerformanceTest.php +3 −4 Original line number Diff line number Diff line Loading @@ -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()); Loading Loading @@ -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()); Loading Loading @@ -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()); Loading
core/tests/Drupal/FunctionalJavascriptTests/PerformanceTestBase.php +14 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ namespace Drupal\FunctionalJavascriptTests; use Drupal\Core\Database\Database; use Drupal\Tests\PerformanceTestTrait; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -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} */ Loading
core/tests/Drupal/Tests/PerformanceTestTrait.php +22 −0 Original line number Diff line number Diff line Loading @@ -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", ); } }