Make HTTP tests more reliable

This commit is contained in:
Dan Stillman 2019-12-23 04:29:41 -05:00
parent 0b9f463b9f
commit 12ccbf45c8

View file

@ -54,6 +54,11 @@ describe("Zotero.HTTP", function () {
server.autoRespond = true;
});
afterEach(async function () {
// Allow requests to settle
await Zotero.Promise.delay(50);
});
after(function* () {
var defer = new Zotero.Promise.defer();
httpd.stop(() => defer.resolve());
@ -173,13 +178,13 @@ describe("Zotero.HTTP", function () {
spy = sinon.spy(Zotero.HTTP, "_requestInternal");
setTimeout(() => {
cancel();
}, 50);
}, 80);
var e = await getPromiseError(
Zotero.HTTP.request(
"GET",
baseURL + "error",
{
errorDelayIntervals: [10, 10, 100],
errorDelayIntervals: [10, 10, 150],
cancellerReceiver: function () {
cancel = arguments[0];
}
@ -187,7 +192,7 @@ describe("Zotero.HTTP", function () {
)
);
assert.instanceOf(e, Zotero.HTTP.CancelledException);
assert.isTrue(spy.calledTwice);
assert.equal(spy.callCount, 3);
});
it("should obey Retry-After for 503", function* () {
@ -224,7 +229,7 @@ describe("Zotero.HTTP", function () {
});
spy = sinon.spy(Zotero.HTTP, "_requestInternal");
yield Zotero.HTTP.request("GET", baseURL + "error");
assert.isTrue(spy.calledThrice);
assert.equal(3, spy.callCount);
// DEBUG: Why are these slightly off?
assert.approximately(delayStub.args[0][0], 5 * 1000, 5);
assert.approximately(delayStub.args[1][0], 10 * 1000, 5);