function TopBarPerformanceTest::testTopBarPerformance
Tests performance for anonymous users is not affected by the Top Bar.
File
-
core/
modules/ navigation/ tests/ src/ FunctionalJavascript/ TopBarPerformanceTest.php, line 39
Class
- TopBarPerformanceTest
- Tests the performance impacts of navigation module.
Namespace
Drupal\Tests\navigation\FunctionalJavascriptCode
public function testTopBarPerformance() : void {
// Request the front page, then immediately clear all object caches, so that
// aggregates and image styles are created on disk but otherwise caches are
// empty.
$this->drupalGet('');
// Give time for big pipe placeholders, asset aggregate requests, and post
// response tasks to finish processing and write to any caches before
// clearing caches again.
sleep(2);
foreach (Cache::getBins() as $bin) {
$bin->deleteAll();
}
// Gather performance data before enabling navigation_top_bar.
$performance_data_before_top_bar = $this->collectPerformanceData(function () {
$this->drupalGet('');
}, 'navigationFrontPageTopBarDisabled');
// Install navigation_top_bar module.
\Drupal::service('module_installer')->install([
'navigation_top_bar',
]);
// Clear caches to prep for another performance data collect.
foreach (Cache::getBins() as $bin) {
$bin->deleteAll();
}
// Gather performance data after enabling navigation_top_bar.
$performance_data_after_top_bar = $this->collectPerformanceData(function () {
$this->drupalGet('');
}, 'navigationFrontPageTopBarEnabled');
// Ensure that there is no change to performance metrics from the Top Bar.
// Anonymous users should never see the Top Bar.
$this->assertMetrics([
'QueryCount' => $performance_data_before_top_bar->getQueryCount(),
'CacheGetCount' => $performance_data_before_top_bar->getCacheGetCount(),
'CacheSetCount' => $performance_data_before_top_bar->getCacheSetCount(),
'CacheDeleteCount' => $performance_data_before_top_bar->getCacheDeleteCount(),
'CacheTagChecksumCount' => $performance_data_before_top_bar->getCacheTagChecksumCount(),
'CacheTagIsValidCount' => $performance_data_before_top_bar->getCacheTagIsValidCount(),
'CacheTagInvalidationCount' => $performance_data_before_top_bar->getCacheTagInvalidationCount(),
], $performance_data_after_top_bar);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.