doing wait for /sync request to receive message, doesn't work well
just poll every 200ms, feels way faster as before we were probably missing /sync requests
This commit is contained in:
parent
28bba4952b
commit
34171eab8c
2 changed files with 14 additions and 33 deletions
|
@ -161,15 +161,6 @@ 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 */
|
/** wait for a /sync request started after this call that gets a 200 response */
|
||||||
async waitForNextSuccessfulSync() {
|
async waitForNextSuccessfulSync() {
|
||||||
const syncUrls = [];
|
const syncUrls = [];
|
||||||
|
|
|
@ -54,31 +54,21 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
|
||||||
|
|
||||||
let lastMessage = null;
|
let lastMessage = null;
|
||||||
let isExpectedMessage = false;
|
let isExpectedMessage = false;
|
||||||
|
let totalTime = 0;
|
||||||
|
while (!isExpectedMessage) {
|
||||||
try {
|
try {
|
||||||
lastMessage = await getLastMessage();
|
lastMessage = await getLastMessage();
|
||||||
isExpectedMessage = lastMessage &&
|
isExpectedMessage = lastMessage &&
|
||||||
lastMessage.body === expectedMessage.body &&
|
lastMessage.body === expectedMessage.body &&
|
||||||
lastMessage.sender === expectedMessage.sender;
|
lastMessage.sender === expectedMessage.sender
|
||||||
} catch(ex) {}
|
} catch(err) {}
|
||||||
// first try to see if the message is already the last message in the timeline
|
if (totalTime > 5000) {
|
||||||
if (isExpectedMessage) {
|
throw new Error("timed out after 5000ms");
|
||||||
assertMessage(lastMessage, expectedMessage);
|
|
||||||
} else {
|
|
||||||
await session.waitForSyncResponseWith(async (response) => {
|
|
||||||
const body = await response.text();
|
|
||||||
if (expectedMessage.encrypted) {
|
|
||||||
return body.indexOf(expectedMessage.sender) !== -1 &&
|
|
||||||
body.indexOf("m.room.encrypted") !== -1;
|
|
||||||
} else {
|
|
||||||
return body.indexOf(expectedMessage.body) !== -1;
|
|
||||||
}
|
}
|
||||||
});
|
totalTime += 200;
|
||||||
// wait a bit for the incoming event to be rendered
|
await session.delay(200);
|
||||||
await session.delay(1000);
|
|
||||||
lastMessage = await getLastMessage();
|
|
||||||
assertMessage(lastMessage, expectedMessage);
|
|
||||||
}
|
}
|
||||||
|
assertMessage(lastMessage, expectedMessage);
|
||||||
session.log.done();
|
session.log.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue