Skip to content

Commit 3d03c16

Browse files
committed
Add tests cases for negative freshness TTL
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent bb44412 commit 3d03c16

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,41 @@ public function test_add_url_metric( int $viewport_width, string $exception ): v
260260
public function data_provider_test_is_complete(): array {
261261
// Note: Test cases for empty URL Metrics and for exact sample size are already covered in the test_add_url_metric() method.
262262
return array(
263-
'old_url_metric' => array(
263+
'old_url_metric' => array(
264264
'url_metric' => $this->get_sample_url_metric(
265265
array(
266266
'timestamp' => microtime( true ) - ( HOUR_IN_SECONDS + 1 ),
267267
'etag' => md5( '' ),
268268
)
269269
),
270+
'freshness_ttl' => HOUR_IN_SECONDS,
270271
'expected_is_group_complete' => false,
271272
),
272-
'etag_mismatch' => array(
273+
'etag_mismatch' => array(
273274
'url_metric' => $this->get_sample_url_metric( array( 'etag' => md5( 'different_etag' ) ) ),
275+
'freshness_ttl' => HOUR_IN_SECONDS,
274276
'expected_is_group_complete' => false,
275277
),
276-
'etag_match' => array(
278+
'etag_match' => array(
277279
'url_metric' => $this->get_sample_url_metric( array( 'etag' => md5( '' ) ) ),
280+
'freshness_ttl' => HOUR_IN_SECONDS,
278281
'expected_is_group_complete' => true,
279282
),
283+
'negative_ttl_with_old_url_metric' => array(
284+
'url_metric' => $this->get_sample_url_metric(
285+
array(
286+
'timestamp' => microtime( true ) - ( WEEK_IN_SECONDS * 4 ),
287+
'etag' => md5( '' ),
288+
)
289+
),
290+
'freshness_ttl' => -HOUR_IN_SECONDS,
291+
'expected_is_group_complete' => true,
292+
),
293+
'negative_ttl_with_etag_mismatch' => array(
294+
'url_metric' => $this->get_sample_url_metric( array( 'etag' => md5( 'different_etag' ) ) ),
295+
'freshness_ttl' => -HOUR_IN_SECONDS,
296+
'expected_is_group_complete' => false,
297+
),
280298
);
281299
}
282300

@@ -287,8 +305,8 @@ public function data_provider_test_is_complete(): array {
287305
*
288306
* @dataProvider data_provider_test_is_complete
289307
*/
290-
public function test_is_complete( OD_URL_Metric $url_metric, bool $expected_is_group_complete ): void {
291-
$collection = new OD_URL_Metric_Group_Collection( array(), md5( '' ), array( 768 ), 1, HOUR_IN_SECONDS );
308+
public function test_is_complete( OD_URL_Metric $url_metric, int $freshness_ttl, bool $expected_is_group_complete ): void {
309+
$collection = new OD_URL_Metric_Group_Collection( array(), md5( '' ), array( 768 ), 1, $freshness_ttl );
292310
$group = $collection->get_first_group();
293311

294312
$group->add_url_metric( $url_metric );

0 commit comments

Comments
 (0)