Fix incorrect retries if multiple HTTP.request() calls get 500s
https://forums.zotero.org/discussion/comment/425814/#Comment_425814 The passed intervals array was modified, so after a request() got a 500, subsequent calls would start with longer delays and eventually start retrying immediately.
This commit is contained in:
parent
437b457134
commit
6a1f0251cd
2 changed files with 24 additions and 0 deletions
|
@ -288,6 +288,29 @@ describe("Zotero.HTTP", function () {
|
|||
assert.approximately(delayStub.args[0][0], 5 * 1000, 5);
|
||||
assert.approximately(delayStub.args[1][0], 10 * 1000, 5);
|
||||
});
|
||||
|
||||
it("should start with first interval on new request() call", async function () {
|
||||
var called = 0;
|
||||
server.respond(function (req) {
|
||||
if (req.method == "GET" && req.url.startsWith(baseURL + "error")) {
|
||||
if (called < 1) {
|
||||
req.respond(500, {}, "");
|
||||
}
|
||||
else {
|
||||
req.respond(200, {}, "");
|
||||
}
|
||||
}
|
||||
called++;
|
||||
});
|
||||
spy = sinon.spy(Zotero.HTTP, "_requestInternal");
|
||||
var errorDelayIntervals = [20];
|
||||
await Zotero.HTTP.request("GET", baseURL + "error1", { errorDelayIntervals })
|
||||
called = 0;
|
||||
await Zotero.HTTP.request("GET", baseURL + "error2", { errorDelayIntervals }),
|
||||
assert.equal(4, spy.callCount);
|
||||
assert.equal(delayStub.args[0][0], 20);
|
||||
assert.equal(delayStub.args[1][0], 20);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue