diff --git a/toolkit/devtools/server/actors/animation.js b/toolkit/devtools/server/actors/animation.js index 12d468e10014..d1a4de6e0361 100644 --- a/toolkit/devtools/server/actors/animation.js +++ b/toolkit/devtools/server/actors/animation.js @@ -483,7 +483,17 @@ let AnimationPlayerFront = FrontClass(AnimationPlayerActor, { return; } - this.autoRefreshTimer = setInterval(this.refreshState.bind(this), interval); + this.autoRefreshTimer = setInterval(() => { + // Save the refresh promise for tests. The tests need to detect when the + // last request completes or they might finish too early. + // Storing the latest Promise is enough to know that there is no pending + // requests left as p.js guarantees the last request will get the reply + // last. + this.pendingRefreshStatePromise = this.refreshState(); + this.pendingRefreshStatePromise.then(() => { + this.pendingRefreshStatePromise = null; + }); + }, interval); }, /** diff --git a/toolkit/devtools/server/tests/browser/browser_animation_actors_05.js b/toolkit/devtools/server/tests/browser/browser_animation_actors_05.js index 8fceb167b257..515b4b9adf4c 100644 --- a/toolkit/devtools/server/tests/browser/browser_animation_actors_05.js +++ b/toolkit/devtools/server/tests/browser/browser_animation_actors_05.js @@ -45,7 +45,13 @@ add_task(function*() { info("Stop the auto-refresh"); player.stopAutoRefresh(); - resolve(); + if (player.pendingRefreshStatePromise) { + // A new request was fired before we had chance to stop it. Wait for + // it to complete. + player.pendingRefreshStatePromise.then(resolve); + } else { + resolve(); + } } }; player.on(player.AUTO_REFRESH_EVENT, onNewState);