Attempts to deflakify the joining test

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 /publicRooms and /initialSync in the joining
test.
This commit is contained in:
Richard van der Hoff 2017-06-14 16:07:40 +01:00
parent 27d5704978
commit 6f2eee1f03
2 changed files with 11 additions and 9 deletions

View File

@ -68,7 +68,7 @@ describe('joining a room', function () {
} }
}); });
it('should not get stuck at a spinner', function(done) { it('should not get stuck at a spinner', function() {
var ROOM_ALIAS = '#alias:localhost'; var ROOM_ALIAS = '#alias:localhost';
var ROOM_ID = '!id:localhost'; var ROOM_ID = '!id:localhost';
@ -140,12 +140,14 @@ describe('joining a room', function () {
.respond(401, {errcode: 'M_GUEST_ACCESS_FORBIDDEN'}); .respond(401, {errcode: 'M_GUEST_ACCESS_FORBIDDEN'});
return q.all([ return q.all([
httpBackend.flush('/directory/room/'+encodeURIComponent(ROOM_ALIAS)), httpBackend.flush('/directory/room/'+encodeURIComponent(ROOM_ALIAS), 1, 200),
httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync"), httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync", 1, 200),
]); ]);
}).then(() => { }).then(() => {
httpBackend.verifyNoOutstandingExpectation(); httpBackend.verifyNoOutstandingExpectation();
return q.delay(1);
}).then(() => {
// we should now have a roomview, with a preview bar // we should now have a roomview, with a preview bar
roomView = ReactTestUtils.findRenderedComponentWithType( roomView = ReactTestUtils.findRenderedComponentWithType(
matrixChat, RoomView); matrixChat, RoomView);
@ -208,7 +210,7 @@ describe('joining a room', function () {
}).then(() => { }).then(() => {
// now the room should have loaded // now the room should have loaded
expect(roomView.state.room).toExist(); expect(roomView.state.room).toExist();
}).done(done, done); });
}); });
}); });
}); });

View File

@ -46,9 +46,8 @@ HttpBackend.prototype = {
const defer = q.defer(); const defer = q.defer();
const self = this; const self = this;
let flushed = 0; let flushed = 0;
let triedWaiting = false;
if (waitTime === undefined) { if (waitTime === undefined) {
waitTime = 5; waitTime = 10;
} }
function log(msg) { function log(msg) {
@ -60,6 +59,8 @@ HttpBackend.prototype = {
+ " waitTime=" + waitTime + " waitTime=" + waitTime
+ ")", + ")",
); );
const endTime = waitTime + Date.now();
const tryFlush = function() { const tryFlush = function() {
// if there's more real requests and more expected requests, flush 'em. // if there's more real requests and more expected requests, flush 'em.
log(` trying to flush => reqs=[${self.requests}] ` + log(` trying to flush => reqs=[${self.requests}] ` +
@ -75,12 +76,11 @@ HttpBackend.prototype = {
log(` flushed. Trying for more.`); log(` flushed. Trying for more.`);
setTimeout(tryFlush, 0); 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 // we may not have made the request yet, wait a generous amount of
// time before giving up. // time before giving up.
log(` nothing to flush yet; waiting for requests.`); log(` nothing to flush yet; waiting for requests.`);
setTimeout(tryFlush, waitTime); setTimeout(tryFlush, 5);
triedWaiting = true;
} else { } else {
if (flushed === 0) { if (flushed === 0) {
log("nothing to flush; giving up"); log("nothing to flush; giving up");