Skip to content

Commit

Permalink
Bug 1865324 [wpt PR 43228] - compute pressure: Try to exit earlier in…
Browse files Browse the repository at this point in the history
… the rate obfuscation web test, a=testonly

Automatic update from web-platform-tests
compute pressure: Try to exit earlier in the rate obfuscation web test

This test is known to be long and apparently times out
on some Mac bots.

This patch is reducing the test execution time by exiting
as soon as the test pass condition is met.

The sampling frequency has been increased to shorten
execution time.

Bug: 1501324
Change-Id: I7f418b5342013b1687099d9a46c7349e67b0decf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5033414
Commit-Queue: Raphael Kubo Da Costa <[email protected]>
Reviewed-by: Raphael Kubo Da Costa <[email protected]>
Reviewed-by: Fr <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1231208}

--

wpt-commits: e019315897e3713e2cafb6d462cddf12fcbc67d4
wpt-pr: 43228
  • Loading branch information
arskama authored and moz-wptsync-bot committed Dec 12, 2023
1 parent d7e9827 commit 9a6699c
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,31 @@
'use strict';

pressure_test(async (t, mockPressureService) => {
const sampleRateInHz = 10;
const sampleRateInHz = 25;
const readings = ['nominal', 'fair', 'serious', 'critical'];
// Normative values for rate obfuscation parameters.
// https://w3c.github.io/compute-pressure/#rate-obfuscation-normative-parameters.
const minPenaltyTimeInMs = 5000;
const maxChangesThreshold = 100;
const changes = await new Promise(async resolve => {
const minChangesThreshold = 50;
await new Promise(async resolve => {
const observerChanges = [];
const observer = new PressureObserver(changes => {
if (observerChanges.length >= minChangesThreshold) {
// Add an assert to the maximum threshold possible.
t.step(() => {
assert_less_than_equal(observerChanges.length, maxChangesThreshold,
"Sample count reaching maxChangesThreshold.");
});

if (observerChanges.length > 0) {
const lastSample = observerChanges.at(-1);
if ((changes[0].time - lastSample[0].time) >= minPenaltyTimeInMs) {
observer.disconnect();
resolve();
}
}
}
observerChanges.push(changes);
}, {sampleRate: sampleRateInHz});

Expand All @@ -25,27 +41,12 @@ pressure_test(async (t, mockPressureService) => {
// pressureChanges.length, as system load and browser optimizations can
// cause the actual timer used by mockPressureService to deliver readings
// to be a bit slower or faster than requested.
while (observerChanges.length <= maxChangesThreshold) {
while (true) {
mockPressureService.setPressureUpdate(
'cpu', readings[i++ % readings.length]);
await t.step_wait(
() => mockPressureService.updatesDelivered() >= i,
`At least ${i} readings have been delivered`);
}
observer.disconnect();
resolve(observerChanges);
});

assert_equals(changes.length, (maxChangesThreshold + 1));

let gotPenalty = false;
for (let i = 0; i < changes.length; i++) {
// Because penalty should be triggered once, one timestamp difference must
// at least bigger or equal to the minimum penalty time specified.
if ((changes[i + 1][0].time - changes[i][0].time) >= minPenaltyTimeInMs) {
gotPenalty = true;
break;
}
}
assert_true(gotPenalty);
}, 'Rate obfuscation mitigation should have been triggered, when changes is higher than minimum changes before penalty');

0 comments on commit 9a6699c

Please sign in to comment.