-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add queues shutdown * initial queue tests file * remove unused deps * don't drain queues on shutdown
- Loading branch information
Showing
4 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
}); | ||
}); |