Skip to content

Commit b96df7c

Browse files
committed
Use the most-frequently used ETag as the current ETag
1 parent 119c093 commit b96df7c

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

plugins/optimization-detective/tests/test-class-od-url-metrics-group.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,20 +443,26 @@ public function data_provider_test_get_lcp_element_when_group_half_stale(): arra
443443
* @param bool $order_reversed Whether the order of URL Metrics should be reversed.
444444
*/
445445
public function test_get_lcp_element_when_group_half_stale( bool $order_reversed ): void {
446-
$current_etag = 'f8527651f96776745f88cc49df70b62d';
447-
448446
$url_metrics_data = json_decode( file_get_contents( __DIR__ . '/data/url-metrics/tablet-viewport-half-stale.json' ), true );
449447
if ( $order_reversed ) {
450448
$url_metrics_data = array_reverse( $url_metrics_data );
451449
}
450+
$url_metrics = array();
451+
$etag_counts = array();
452+
foreach ( $url_metrics_data as $url_metric_data ) {
453+
$url_metric = new OD_URL_Metric( $url_metric_data );
454+
$etag = $url_metric->get_etag();
455+
if ( ! isset( $etag_counts[ $etag ] ) ) {
456+
$etag_counts[ $etag ] = 0;
457+
}
458+
++$etag_counts[ $etag ];
459+
$url_metrics[] = $url_metric;
460+
}
461+
arsort( $etag_counts );
462+
$current_etag = key( $etag_counts ); // The ETag used most often.
452463

453464
$collection = new OD_URL_Metric_Group_Collection(
454-
array_map(
455-
static function ( array $url_metric_data ): OD_URL_Metric {
456-
return new OD_URL_Metric( $url_metric_data );
457-
},
458-
$url_metrics_data
459-
),
465+
$url_metrics,
460466
$current_etag,
461467
array( 480, 600, 782 ),
462468
3,

0 commit comments

Comments
 (0)