Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Weblate 2017-06-15 15:29:41 +00:00
commit 28753c451d
2 changed files with 28 additions and 29 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';
@ -119,8 +119,8 @@ describe('joining a room', function () {
httpBackend.when('POST', '/publicRooms').respond(200, {chunk: []}); httpBackend.when('POST', '/publicRooms').respond(200, {chunk: []});
httpBackend.when('GET', '/thirdparty/protocols').respond(200, {}); httpBackend.when('GET', '/thirdparty/protocols').respond(200, {});
return q.all([ return q.all([
httpBackend.flush('/publicRooms'),
httpBackend.flush('/thirdparty/protocols'), httpBackend.flush('/thirdparty/protocols'),
httpBackend.flush('/publicRooms'),
]); ]);
}).then(() => { }).then(() => {
var roomDir = ReactTestUtils.findRenderedComponentWithType( var roomDir = ReactTestUtils.findRenderedComponentWithType(
@ -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

@ -13,7 +13,7 @@ function HttpBackend() {
// the request function dependency that the SDK needs. // the request function dependency that the SDK needs.
this.requestFn = function(opts, callback) { this.requestFn = function(opts, callback) {
const req = new Request(opts, callback); const req = new Request(opts, callback);
console.log("HTTP backend received request: " + req); console.log(`${Date.now()} HTTP backend received request: ${req}`);
self.requests.push(req); self.requests.push(req);
const abort = function() { const abort = function() {
@ -64,7 +64,7 @@ HttpBackend.prototype = {
* @param {string} path The path to flush (optional) default: all. * @param {string} path The path to flush (optional) default: all.
* @param {integer} numToFlush The number of things to flush (optional), default: all. * @param {integer} numToFlush The number of things to flush (optional), default: all.
* @param {integer=} waitTime The time (in ms) to wait for a request to happen. * @param {integer=} waitTime The time (in ms) to wait for a request to happen.
* default: 5 * default: 100
* *
* @return {Promise} resolves when there is nothing left to flush, with the * @return {Promise} resolves when there is nothing left to flush, with the
* number of requests flushed * number of requests flushed
@ -73,49 +73,46 @@ 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 = 100;
} }
console.log(
"HTTP backend flushing... (path=" + path function log(msg) {
console.log(`${Date.now()} flush[${path || ''}]: ${msg}`);
}
log("HTTP backend flushing... (path=" + path
+ " numToFlush=" + numToFlush + " numToFlush=" + numToFlush
+ " 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.
console.log( log(` trying to flush => reqs=[${self.requests}] ` +
" trying to flush queue => reqs=[" + self.requests `expected=[${self.expectedRequests}]`,
+ "] expected=[" + self.expectedRequests
+ "]",
); );
if (self._takeFromQueue(path)) { if (self._takeFromQueue(path)) {
// try again on the next tick. // try again on the next tick.
flushed += 1; flushed += 1;
if (numToFlush && flushed === numToFlush) { if (numToFlush && flushed === numToFlush) {
console.log(" Flushed assigned amount:", numToFlush); log(`Flushed assigned amount: ${numToFlush}`);
defer.resolve(flushed); defer.resolve(flushed);
} else { } else {
console.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.
console.log( log(` nothing to flush yet; waiting for requests.`);
" nothing to flush yet; waiting " + waitTime + setTimeout(tryFlush, 5);
"ms for requests.")
setTimeout(tryFlush, waitTime);
triedWaiting = true;
} else { } else {
if (flushed === 0) { if (flushed === 0) {
console.log(" nothing to flush; giving up"); log("nothing to flush; giving up");
} else { } else {
console.log( log(`no more flushes after flushing ${flushed} requests`);
" no more flushes after flushing", flushed,
"requests",
);
} }
defer.resolve(flushed); defer.resolve(flushed);
} }
@ -165,7 +162,7 @@ HttpBackend.prototype = {
matchingReq.checks[j](req); matchingReq.checks[j](req);
} }
testResponse = matchingReq.response; testResponse = matchingReq.response;
console.log(" responding to %s", matchingReq.path); console.log(`${Date.now()} responding to ${matchingReq.path}`);
let body = testResponse.body; let body = testResponse.body;
if (Object.prototype.toString.call(body) == "[object Function]") { if (Object.prototype.toString.call(body) == "[object Function]") {
body = body(req.path, req.data); body = body(req.path, req.data);