Skip to content

Commit

Permalink
test: Fix test failure waiting for passed time (#6580)
Browse files Browse the repository at this point in the history
In some rare cases, particularly on Fuchsia-based Chromecasts at the moment, I am seeing test failures where the test is waiting for a time that has already passed. It appears that the `timeupdate` events may be missed in some cases. The `currentTime` appears to be less than the target at the last `timeupdate` event, then the time progresses internally, then a buffering state is hit and no new `timeupdate` events fire. So the Waiter class should use a timer for this as it does for many other types of waits.
  • Loading branch information
joeyparrish committed May 11, 2024
1 parent ddabe93 commit 04d816c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/test/util/waiter.js
Expand Up @@ -115,25 +115,31 @@ shaka.test.Waiter = class {
const goalName = 'movement from ' + mediaElement.currentTime +
' to ' + timeGoal;

// The cleanup on timeout
let timer = null;
const cleanup = () => {
if (timer) {
timer.stop();
}
this.eventManager_.unlisten(mediaElement, 'timeupdate');
this.eventManager_.unlisten(mediaElement, 'ended');
};

// The conditions for success
const p = new Promise((resolve) => {
const check = () => {
if (mediaElement.currentTime >= timeGoal || mediaElement.ended) {
this.eventManager_.unlisten(mediaElement, 'timeupdate');
this.eventManager_.unlisten(mediaElement, 'ended');
cleanup();
resolve();
}
};

timer = new shaka.util.Timer(check);
timer.tickEvery(/* seconds= */ 1);
this.eventManager_.listen(mediaElement, 'timeupdate', check);
this.eventManager_.listen(mediaElement, 'ended', check);
});

// The cleanup on timeout
const cleanup = () => {
this.eventManager_.unlisten(mediaElement, 'timeupdate');
this.eventManager_.unlisten(mediaElement, 'ended');
};

return this.waitUntilGeneric_(goalName, p, cleanup, mediaElement);
}

Expand Down

0 comments on commit 04d816c

Please sign in to comment.