Verified Commit 506ccd4e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3445285 by catch, longwave, larowlan, quietone: Add extra page request...

Issue #3445285 by catch, longwave, larowlan, quietone: Add extra page request to the across pages asset performance test

(cherry picked from commit 8654d2b8)
parent 18daefd7
Loading
Loading
Loading
Loading
Loading
+24 −20
Original line number Diff line number Diff line
@@ -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 () {
  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');
    }, 'umamiFrontAndRecipePages');
    return $performance_data;
    sleep(2);
    $this->drupalGet('recipes');
    sleep(2);
    $this->drupalGet('recipes/deep-mediterranean-quiche');
  }

}
+6 −2
Original line number Diff line number Diff line
@@ -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 {
    // 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;
  }

}