Skip to content

Commit

Permalink
Attempts to deflakify the joining test
Browse files Browse the repository at this point in the history
Treat the waitTime passed into `flush` as a timeout rather than a
time-between-loops, so that we can pass in bigger times and not slow the tests
down too much.

Bump the timeout when waiting for /initialSync in the joining test.
  • Loading branch information
richvdh committed Jun 14, 2017
1 parent b1754a2 commit 9a5d170
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion test/app-tests/joining.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ describe('joining a room', function () {

return q.all([
httpBackend.flush('/directory/room/'+encodeURIComponent(ROOM_ALIAS)),
httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync"),
httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync", 1, 20),
]);
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();

return q.delay(1);
}).then(() => {
// we should now have a roomview, with a preview bar
roomView = ReactTestUtils.findRenderedComponentWithType(
matrixChat, RoomView);
Expand Down
10 changes: 5 additions & 5 deletions test/mock-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ HttpBackend.prototype = {
const defer = q.defer();
const self = this;
let flushed = 0;
let triedWaiting = false;
if (waitTime === undefined) {
waitTime = 5;
waitTime = 10;
}

function log(msg) {
Expand All @@ -60,6 +59,8 @@ HttpBackend.prototype = {
+ " waitTime=" + waitTime
+ ")",
);
const endTime = waitTime + Date.now();

const tryFlush = function() {
// if there's more real requests and more expected requests, flush 'em.
log(` trying to flush => reqs=[${self.requests}] ` +
Expand All @@ -75,12 +76,11 @@ HttpBackend.prototype = {
log(` flushed. Trying for more.`);
setTimeout(tryFlush, 0);
}
} else if (flushed === 0 && !triedWaiting) {
} else if (flushed === 0 && Date.now() < endTime) {
// we may not have made the request yet, wait a generous amount of
// time before giving up.
log(` nothing to flush yet; waiting for requests.`);
setTimeout(tryFlush, waitTime);
triedWaiting = true;
setTimeout(tryFlush, 5);
} else {
if (flushed === 0) {
log("nothing to flush; giving up");
Expand Down

0 comments on commit 9a5d170

Please sign in to comment.