forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compute pressure: Increase timeouts and drop uses of t.step_wait()
- When we need to wait to verify that an update was _not_ sent, update the timeout from 1 second to 3 seconds (and mark tests with timeout=long). 1 second is sometimes too little for busy bots such as the mac-rel and win-rel ones, which can lead to flakiness or, in this case, updates not being delivered for the wrong reason (i.e. the browser process just has not had time to process the update_virtual_pressure_source() call). - Introduce a new SyncPressureObserver wrapper class that stores multiple pressure updates and allows users to synchronously wait for the next one using Promises. This is useful for tests that need to send and wait for multiple updates: instead of polling using t.step_wait(), these tests can just use this class to wait for a Promise to resolve when an update is delivered. Bug: 347031400 Change-Id: I7880577757d71678e612d912716f4f12020a5fef Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5912856 Reviewed-by: Reilly Grant <[email protected]> Commit-Queue: Reilly Grant <[email protected]> Auto-Submit: Raphael Kubo Da Costa <[email protected]> Cr-Commit-Position: refs/heads/main@{#1365092}
- Loading branch information
1 parent
07001d0
commit 5f9ff49
Showing
7 changed files
with
105 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Wrapper around a PressureObserver that: | ||
// 1. Receives and stores multiple updates. | ||
// 2. Allows callers to synchronously wait for an update. | ||
// | ||
// Usage: | ||
// const syncObserver = new SyncPressureObserver(t); | ||
// await syncObserver.observer().observe('cpu'); | ||
// await update_virtual_pressure_source(..); | ||
// await syncObserver.waitForUpdate(); | ||
// const changes = syncObserver.changes(); | ||
// assert_equals(changes[0][0].state, 'nominal'); | ||
class SyncPressureObserver { | ||
#observer = null; | ||
#changes = []; | ||
|
||
#promisesWithResolver = [Promise.withResolvers()]; | ||
#currentPromisePosition = 0; | ||
#currentResolvePosition = 0; | ||
|
||
constructor(t) { | ||
this.#observer = new PressureObserver(changes => { | ||
this.#changes.push(changes); | ||
|
||
if (this.#currentResolvePosition === this.#promisesWithResolver.length) { | ||
this.#promisesWithResolver.push(Promise.withResolvers()); | ||
} | ||
this.#promisesWithResolver[this.#currentResolvePosition++].resolve(); | ||
}); | ||
t.add_cleanup(() => {this.#observer.disconnect()}); | ||
} | ||
|
||
changes() { | ||
return this.#changes; | ||
} | ||
|
||
observer() { | ||
return this.#observer; | ||
} | ||
|
||
async waitForUpdate() { | ||
if (this.#currentPromisePosition === this.#promisesWithResolver.length) { | ||
this.#promisesWithResolver.push(Promise.withResolvers()); | ||
} | ||
await this.#promisesWithResolver[this.#currentPromisePosition++].promise; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters