From 36708cc5db5cc303904884bc9ea50ac76bcb3a5c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 14 Sep 2018 14:45:40 +0200 Subject: [PATCH] wait for next sync before inspecting memberlist before we needed a 10s delay here to make the test work reliable, this should be faster in the best case. --- src/scenarios/lazy-loading.js | 5 +++-- src/session.js | 27 +++++++++++++++++++++++++++ src/usecases/timeline.js | 5 +---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/scenarios/lazy-loading.js b/src/scenarios/lazy-loading.js index a606cc0421..15826af568 100644 --- a/src/scenarios/lazy-loading.js +++ b/src/scenarios/lazy-loading.js @@ -102,7 +102,8 @@ async function joinCharliesWhileAliceIsOffline(alice, charly6to10) { await member6.talk("where is charly?"); } member6.log.unmute().done(); - await delay(1000); + const catchupPromise = alice.waitForNextSuccessfulSync(); await alice.setOffline(false); - await delay(1000); + await catchupPromise; + await delay(2000); } diff --git a/src/session.js b/src/session.js index 82a66fda39..7ea980bd32 100644 --- a/src/session.js +++ b/src/session.js @@ -161,6 +161,33 @@ module.exports = class RiotSession { }); } + waitForSyncResponseWith(predicate) { + return this.page.waitForResponse(async (response) => { + if (response.request().url().indexOf("/sync") === -1) { + return false; + } + return predicate(response); + }); + } + + /** wait for a /sync request started after this call that gets a 200 response */ + async waitForNextSuccessfulSync() { + const syncUrls = []; + function onRequest(request) { + if (request.url().indexOf("/sync") !== -1) { + syncUrls.push(request.url()); + } + } + + this.page.on('request', onRequest); + + await this.page.waitForResponse((response) => { + return syncUrls.includes(response.request().url()) && response.status() === 200; + }); + + this.page.removeListener('request', onRequest); + } + goto(url) { return this.page.goto(url); } diff --git a/src/usecases/timeline.js b/src/usecases/timeline.js index 466d7fb222..dce0203660 100644 --- a/src/usecases/timeline.js +++ b/src/usecases/timeline.js @@ -64,10 +64,7 @@ module.exports.receiveMessage = async function(session, expectedMessage) { if (isExpectedMessage) { assertMessage(lastMessage, expectedMessage); } else { - await session.page.waitForResponse(async (response) => { - if (response.request().url().indexOf("/sync") === -1) { - return false; - } + await session.waitForSyncResponseWith(async (response) => { const body = await response.text(); if (expectedMessage.encrypted) { return body.indexOf(expectedMessage.sender) !== -1 &&