diff --git a/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php b/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php index 5de39840bb30c8417945a3e406f8160ef1281647..141383657d64c116ffeec739a7ead2afaf1bb630 100644 --- a/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php +++ b/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php @@ -5,7 +5,6 @@ namespace Drupal\Tests\demo_umami\FunctionalJavascript; use Drupal\FunctionalJavascriptTests\PerformanceTestBase; -use Drupal\Tests\PerformanceData; /** * Tests demo_umami profile performance. @@ -23,9 +22,11 @@ class AssetAggregationAcrossPagesTest extends PerformanceTestBase { * Checks the asset requests made when the front and recipe pages are visited. */ public function testFrontAndRecipesPages() { - $performance_data = $this->doRequests(); - $this->assertSame(4, $performance_data->getStylesheetCount()); - $this->assertLessThan(80000, $performance_data->getStylesheetBytes()); + $performance_data = $this->collectPerformanceData(function () { + $this->doRequests(); + }, 'umamiFrontAndRecipePages'); + $this->assertSame(6, $performance_data->getStylesheetCount()); + $this->assertLessThan(125000, $performance_data->getStylesheetBytes()); $this->assertSame(1, $performance_data->getScriptCount()); $this->assertLessThan(7500, $performance_data->getScriptBytes()); } @@ -36,26 +37,29 @@ public function testFrontAndRecipesPages() { public function testFrontAndRecipesPagesAuthenticated() { $user = $this->createUser(); $this->drupalLogin($user); - $this->rebuildAll(); - $performance_data = $this->doRequests(); - $this->assertSame(4, $performance_data->getStylesheetCount()); - $this->assertLessThan(87000, $performance_data->getStylesheetBytes()); - $this->assertSame(1, $performance_data->getScriptCount()); - $this->assertLessThan(125500, $performance_data->getScriptBytes()); + sleep(2); + $performance_data = $this->collectPerformanceData(function () { + $this->doRequests(); + }, 'umamiFrontAndRecipePagesAuthenticated'); + $this->assertSame(6, $performance_data->getStylesheetCount()); + $this->assertLessThan(132500, $performance_data->getStylesheetBytes()); + $this->assertSame(2, $performance_data->getScriptCount()); + $this->assertLessThan(250000, $performance_data->getScriptBytes()); } /** - * Helper to do requests so the above test methods stay in sync. + * Performs a common set of requests so the above test methods stay in sync. */ - protected function doRequests(): PerformanceData { - $performance_data = $this->collectPerformanceData(function () { - $this->drupalGet('<front>'); - // Give additional time for the request and all assets to be returned - // before making the next request. - sleep(2); - $this->drupalGet('articles'); - }, 'umamiFrontAndRecipePages'); - return $performance_data; + protected function doRequests(): void { + $this->drupalGet('<front>'); + // Give additional time for the request and all assets to be returned + // before making the next request. + sleep(2); + $this->drupalGet('articles'); + sleep(2); + $this->drupalGet('recipes'); + sleep(2); + $this->drupalGet('recipes/deep-mediterranean-quiche'); } } diff --git a/core/tests/Drupal/Tests/PerformanceTestTrait.php b/core/tests/Drupal/Tests/PerformanceTestTrait.php index 3ebbf593ef647e4b07c5a2f001fd646dbcd0d0fb..3cecbd18f05ba57f1ce1f48ea18aaac1f39954d1 100644 --- a/core/tests/Drupal/Tests/PerformanceTestTrait.php +++ b/core/tests/Drupal/Tests/PerformanceTestTrait.php @@ -614,8 +614,12 @@ protected function assertCountBetween(int $min, int $max, int $actual) { * Whether the event was triggered by the database cache implementation. */ protected static function isDatabaseCache(DatabaseEvent $event): bool { - $class = str_replace('\\\\', '\\', $event->caller['class']); - return is_a($class, '\Drupal\Core\Cache\DatabaseBackend', TRUE) || is_a($class, '\Drupal\Core\Cache\DatabaseCacheTagsChecksum', TRUE); + // If there is no class, then this is called from a procedural function. + if (isset($event->caller['class'])) { + $class = str_replace('\\\\', '\\', $event->caller['class']); + return is_a($class, '\Drupal\Core\Cache\DatabaseBackend', TRUE) || is_a($class, '\Drupal\Core\Cache\DatabaseCacheTagsChecksum', TRUE); + } + return FALSE; } }