Skip to content

Commit 6f2eee1

Browse files
committed
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.
1 parent 27d5704 commit 6f2eee1

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎test/app-tests/joining.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('joining a room', function () {
6868
}
6969
});
7070

71-
it('should not get stuck at a spinner', function(done) {
71+
it('should not get stuck at a spinner', function() {
7272
var ROOM_ALIAS = '#alias:localhost';
7373
var ROOM_ID = '!id:localhost';
7474

@@ -140,12 +140,14 @@ describe('joining a room', function () {
140140
.respond(401, {errcode: 'M_GUEST_ACCESS_FORBIDDEN'});
141141

142142
return q.all([
143-
httpBackend.flush('/directory/room/'+encodeURIComponent(ROOM_ALIAS)),
144-
httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync"),
143+
httpBackend.flush('/directory/room/'+encodeURIComponent(ROOM_ALIAS), 1, 200),
144+
httpBackend.flush('/rooms/'+encodeURIComponent(ROOM_ID)+"/initialSync", 1, 200),
145145
]);
146146
}).then(() => {
147147
httpBackend.verifyNoOutstandingExpectation();
148148

149+
return q.delay(1);
150+
}).then(() => {
149151
// we should now have a roomview, with a preview bar
150152
roomView = ReactTestUtils.findRenderedComponentWithType(
151153
matrixChat, RoomView);
@@ -208,7 +210,7 @@ describe('joining a room', function () {
208210
}).then(() => {
209211
// now the room should have loaded
210212
expect(roomView.state.room).toExist();
211-
}).done(done, done);
213+
});
212214
});
213215
});
214216
});

‎test/mock-request.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ HttpBackend.prototype = {
4646
const defer = q.defer();
4747
const self = this;
4848
let flushed = 0;
49-
let triedWaiting = false;
5049
if (waitTime === undefined) {
51-
waitTime = 5;
50+
waitTime = 10;
5251
}
5352

5453
function log(msg) {
@@ -60,6 +59,8 @@ HttpBackend.prototype = {
6059
+ " waitTime=" + waitTime
6160
+ ")",
6261
);
62+
const endTime = waitTime + Date.now();
63+
6364
const tryFlush = function() {
6465
// if there's more real requests and more expected requests, flush 'em.
6566
log(` trying to flush => reqs=[${self.requests}] ` +
@@ -75,12 +76,11 @@ HttpBackend.prototype = {
7576
log(` flushed. Trying for more.`);
7677
setTimeout(tryFlush, 0);
7778
}
78-
} else if (flushed === 0 && !triedWaiting) {
79+
} else if (flushed === 0 && Date.now() < endTime) {
7980
// we may not have made the request yet, wait a generous amount of
8081
// time before giving up.
8182
log(` nothing to flush yet; waiting for requests.`);
82-
setTimeout(tryFlush, waitTime);
83-
triedWaiting = true;
83+
setTimeout(tryFlush, 5);
8484
} else {
8585
if (flushed === 0) {
8686
log("nothing to flush; giving up");

0 commit comments

Comments
 (0)