From 12ccbf45c8bbe8b56dd5ed7b14e93bbd01ec93f4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 23 Dec 2019 04:29:41 -0500 Subject: [PATCH] Make HTTP tests more reliable --- test/tests/httpTest.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/tests/httpTest.js b/test/tests/httpTest.js index 18e56d6610..d57703370b 100644 --- a/test/tests/httpTest.js +++ b/test/tests/httpTest.js @@ -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);