From 488794c8225628683ae46b5e39f18c2734ababf0 Mon Sep 17 00:00:00 2001 From: Axe Date: Mon, 23 Oct 2023 14:04:52 +0100 Subject: [PATCH] initial queue tests file --- test/unit-tests/protocol/queues.test.js | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/unit-tests/protocol/queues.test.js diff --git a/test/unit-tests/protocol/queues.test.js b/test/unit-tests/protocol/queues.test.js new file mode 100644 index 00000000..2a8eaf68 --- /dev/null +++ b/test/unit-tests/protocol/queues.test.js @@ -0,0 +1,53 @@ +const sinon = require("sinon"); +const { expect } = require("chai"); +const Queues = require("../../../src/protocol/queues"); + +describe("Queues", () => { + let queue; + let appMock; + let sandbox; + + beforeEach(() => { + sandbox = sinon.createSandbox(); + + appMock = { + logger: { + debug: sinon.stub(), + info: sinon.stub(), + error: sinon.stub() + }, + + _isShutdown: false, + config: { + NUM_RETRIES: 3, + CONCURRENCY: 2 + }, + }; + + queue = new Queues(appMock); + }); + + afterEach(() => { + sandbox.restore(); + }); + + + it("#1.1 - should not run if app is shutting down", async () => { + appMock._isShutdown = true; + await queue.run(sinon.stub(), 5000); + expect(appMock.logger.info.calledOnce).to.be.true; + expect(appMock.logger.info.calledWith("app.shutdown() - closing queues")).to.be.true; + }); + + + it("#1.2 - should not add tasks to the queue if app is shutting down", async () => { + queue.init(); + await queue.shutdown(); + try { + await queue.addQueuedEstimation("token", "account", "source"); + expect.fail("Expected addQueuedEstimation to throw"); + } catch (error) { + expect(error.message).to.include("Queues.addQueuedEstimation(): shutdown"); + } + }); +});