mock-request: improve logging

attempt to make the logging a bit more comprehensible
pull/3956/head
Richard van der Hoff 2017-05-18 13:37:23 +01:00
parent a39a7c8334
commit f60773ae1f
1 changed files with 24 additions and 7 deletions

View File

@ -13,7 +13,7 @@ function HttpBackend() {
// the request function dependency that the SDK needs.
this.requestFn = function(opts, callback) {
const req = new Request(opts, callback);
console.log("HTTP backend received request: %s", req);
console.log("HTTP backend received request: " + req);
self.requests.push(req);
const abort = function() {
@ -51,20 +51,23 @@ HttpBackend.prototype = {
waitTime = 5;
}
console.log(
"HTTP backend flushing... (path=%s numToFlush=%s waitTime=%s)",
path, numToFlush, waitTime,
"HTTP backend flushing... (path=" + path
+ " numToFlush=" + numToFlush
+ " waitTime=" + waitTime
+ ")",
);
const tryFlush = function() {
// if there's more real requests and more expected requests, flush 'em.
console.log(
" trying to flush queue => reqs=[%s] expected=[%s]",
self.requests, self.expectedRequests.map((er) => er.path),
" trying to flush queue => reqs=[" + self.requests
+ "] expected=[" + self.expectedRequests
+ "]",
);
if (self._takeFromQueue(path)) {
// try again on the next tick.
flushed += 1;
if (numToFlush && flushed === numToFlush) {
console.log(" Flushed assigned amount: %s", numToFlush);
console.log(" Flushed assigned amount:", numToFlush);
defer.resolve(flushed);
} else {
console.log(" flushed. Trying for more.");
@ -73,10 +76,20 @@ HttpBackend.prototype = {
} else if (flushed === 0 && !triedWaiting) {
// we may not have made the request yet, wait a generous amount of
// time before giving up.
console.log(
" nothing to flush yet; waiting " + waitTime +
"ms for requests.")
setTimeout(tryFlush, waitTime);
triedWaiting = true;
} else {
console.log(" no more flushes.");
if (flushed === 0) {
console.log(" nothing to flush; giving up");
} else {
console.log(
" no more flushes after flushing", flushed,
"requests",
);
}
defer.resolve(flushed);
}
};
@ -197,6 +210,10 @@ function ExpectedRequest(method, path, data) {
}
ExpectedRequest.prototype = {
toString: function() {
return this.method + " " + this.path
},
/**
* Execute a check when this request has been satisfied.
* @param {Function} fn The function to execute.