function PerformanceTestTrait::assertMetricsByName
Same name and namespace in other branches
- main core/tests/Drupal/Tests/PerformanceTestTrait.php \Drupal\Tests\PerformanceTestTrait::assertMetricsByName()
Asserts metrics against the stored expectations.
Expected queries are stored in the folder named TestClassNameAssertions in the same directory.
Parameters
string $name: A identifier for the expected queries. Must be unique for the given test.
\Drupal\Tests\PerformanceData $performance_data: An instance of the performance data value object.
array $metrics: Customize the number of default metrics to assert in case no data is stored yet.
12 calls to PerformanceTestTrait::assertMetricsByName()
- JsonApiPerformanceTest::testGetIndividual in core/
modules/ jsonapi/ tests/ src/ FunctionalJavascript/ JsonApiPerformanceTest.php - Tests performance of the navigation toolbar.
- OpenTelemetryPerformanceTest::doTestFrontPageAuthenticatedWarmCache in core/
profiles/ demo_umami/ tests/ src/ FunctionalJavascript/ OpenTelemetryPerformanceTest.php - Logs front page tracing data with an authenticated user and warm cache.
- OpenTelemetryPerformanceTest::doTestNodePageAdministrator in core/
profiles/ demo_umami/ tests/ src/ FunctionalJavascript/ OpenTelemetryPerformanceTest.php - Logs node page performance with an administrator.
- OpenTelemetryPerformanceTest::testFrontPageColdCache in core/
profiles/ demo_umami/ tests/ src/ FunctionalJavascript/ OpenTelemetryPerformanceTest.php - Logs front page tracing data with a cold cache.
- OpenTelemetryPerformanceTest::testFrontPageCoolCache in core/
profiles/ demo_umami/ tests/ src/ FunctionalJavascript/ OpenTelemetryPerformanceTest.php - Logs front page tracing data with a lukewarm cache.
File
-
core/
tests/ Drupal/ Tests/ PerformanceTestTrait.php, line 776
Class
- PerformanceTestTrait
- Provides various methods to aid in collecting performance data during tests.
Namespace
Drupal\TestsCode
protected function assertMetricsByName(string $name, PerformanceData $performance_data, array $metrics = []) : void {
$filename = $this->getExpectationsFilename($name, 'yml');
$content = file_exists($filename) ? file_get_contents($filename) : '';
if (!empty($content)) {
$expected = Yaml::decode($content);
}
else {
// No existing data found. Use a default list of metrics to update if no
// custom list is provided.
$expected = array_flip($metrics) ?: [
'QueryCount' => 0,
'CacheGetCount' => 0,
'CacheGetCountByBin' => [],
'CacheSetCount' => 0,
'CacheDeleteCount' => 0,
'CacheTagInvalidationCount' => 0,
'CacheTagLookupQueryCount' => 0,
'CacheTagGroupedLookups' => [],
'ScriptCount' => 0,
'ScriptBytes' => 0,
'StylesheetCount' => 0,
'StylesheetBytes' => 0,
];
}
if (empty($content) || $this->shouldUpdate()) {
foreach ($expected as $name => $metric) {
$expected[$name] = $performance_data->{"get{$name}"}();
}
file_put_contents($filename, Yaml::encode($expected));
}
else {
$this->assertMetrics($expected, $performance_data);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.