Skip to content

Commit

Permalink
compute-pressure: Ensure clean test exit
Browse files Browse the repository at this point in the history
It can happen on certain bots that the pressure updates are still sent
before disconnect() is processed in the mockPressureService, which can
lead in certain cases to receive more updates than allowed in the test.

This patch adds a `gotPenalty` flag, to make sure that at least one
penalty was applied when reaching the maximum allowed updates.

Change-Id: I535b8c21370d14f13f0d6140d1eb2cc043cbeac2
Bug: 1501324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5076963
Reviewed-by: Fr <beaufort.francois@gmail.com>
Commit-Queue: Arnaud Mandy <arnaud.mandy@intel.com>
Reviewed-by: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/main@{#1232652}
  • Loading branch information
arskama authored and chromium-wpt-export-bot committed Dec 4, 2023
1 parent 3c7b862 commit da0a565
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ pressure_test(async (t, mockPressureService) => {
const minPenaltyTimeInMs = 5000;
const maxChangesThreshold = 100;
const minChangesThreshold = 50;
let gotPenalty = false;
await new Promise(async resolve => {
const observerChanges = [];
const observer = new PressureObserver(changes => {
if (observerChanges.length >= minChangesThreshold) {
if (observerChanges.length >= minChangesThreshold && !gotPenalty) {
// 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();
}
const lastSample = observerChanges.at(-1);
if ((changes[0].time - lastSample[0].time) >= minPenaltyTimeInMs) {
// The update delivery might still be working even if
// maxChangesThreshold have been reached and before disconnect() is
// processed. This will corrupt the result for the above t.step().
// Therefore we are adding a flag to dismiss any updates after the
// penalty is detected, which is the condition for the test to pass.
gotPenalty = true;
observer.disconnect();
resolve();
}
}
observerChanges.push(changes);
Expand Down

0 comments on commit da0a565

Please sign in to comment.