Skip to content

Commit

Permalink
initial queue tests file
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmachado committed Oct 23, 2023
1 parent bd7d79f commit 488794c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/unit-tests/protocol/queues.test.js
Original file line number Diff line number Diff line change
@@ -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");
}
});
});

0 comments on commit 488794c

Please sign in to comment.