Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299307

Add PerformanceTestTrait::assertMetrics() so it is easier to write performance tests

$
0
0

Problem/Motivation

The existing performance tests include several assertions, like

    $this->assertSame(0, $performance_data->getQueryCount());
    $this->assertSame(1, $performance_data->getCacheGetCount());
    $this->assertSame(0, $performance_data->getCacheSetCount());
    // ...

This leads to a lot of cut-and-paste when creating new tests, and filling in the numeric values takes some work.

Another problem is that a failing test produces output like this:

Drupal\Tests\demo_umami\FunctionalJavascript\OpenTelemetryFrontPagePerformanceTest::testFrontPagePerformance
Failed asserting that 1 is identical to 3.

/var/www/html/core/profiles/demo_umami/tests/src/FunctionalJavascript/OpenTelemetryFrontPagePerformanceTest.php:51

and then you have to look at Line 51 in the test class to figure out which metric changed.

Steps to reproduce

Proposed resolution

Add a helper method to the PerformanceTestTrait class. The order of the parameters is to be decided, but the function signature should be something like this:

  public function assertMetrics(
    PerformanceData $performance_data,
    ?int $stylesheet_count = NULL,
    ?int $script_count = NULL,
    ?int $stylesheet_bytes = NULL,
    ?int $script_bytes = NULL,
    ?int $query_count = NULL,
    ?int $cache_get_count = NULL,
    ?int $cache_set_count = NULL,
    ?int $cache_delete_count = NULL,
    ?int $cache_tag_checksum_count = NULL,
    ?int $cache_tag_is_valid_count = NULL,
    ?int $cache_tag_invalidation_count = NULL,
  ): void

This method would make an assertion for any non-null argument, and use assertEqualsWithDelta() or PerformanceTestTrait::assertCountBetween() for the byte counts.

Add the optional $message parameter to each assertion so that a failing test tells you which metric is out of range.

Remaining tasks

User interface changes

None

Introduced terminology

None

API changes

Add the public method assertMetrics() to Drupal\Tests\PerformanceTestTrait.

Data model changes

None

Release notes snippet

N/A


Viewing all articles
Browse latest Browse all 299307

Latest Images

Trending Articles



Latest Images