mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 01:35:49 +03:00
Improve logging in mock-request
Try to make it a bit more obvious what's been going on in mock-request: add timestamps to lines, and an identifier so that where we have two flushes in parallel, we can see what's what.
This commit is contained in:
parent
59da904353
commit
27d5704978
1 changed files with 15 additions and 18 deletions
|
@ -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() {
|
||||||
|
@ -50,45 +50,42 @@ HttpBackend.prototype = {
|
||||||
if (waitTime === undefined) {
|
if (waitTime === undefined) {
|
||||||
waitTime = 5;
|
waitTime = 5;
|
||||||
}
|
}
|
||||||
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 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 && !triedWaiting) {
|
||||||
// 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 +
|
|
||||||
"ms for requests.")
|
|
||||||
setTimeout(tryFlush, waitTime);
|
setTimeout(tryFlush, waitTime);
|
||||||
triedWaiting = true;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +135,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);
|
||||||
|
|
Loading…
Reference in a new issue