Skip to content

Commit

Permalink
Refactoring index test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyudmil Danailov authored and Lyudmil Danailov committed Jan 18, 2024
1 parent bea9610 commit 0739740
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const BaseWorker = require('../lib/worker_base');
const { Exporter } = require('../lib/kafka_storage');
const { worker } = require('../blockchains/eth/eth_worker');
const zkClientAsync = require('../lib/zookeeper_client_async');
const TaskManager = require('../lib/task_manager');

describe('Main', () => {
const constants = {
Expand Down Expand Up @@ -159,15 +160,20 @@ describe('Main', () => {
mainInstance.exporter = new Exporter('test-exporter');
sinon.stub(worker.prototype, 'init').resolves();
sinon.stub(mainInstance, 'handleInitPosition').resolves();
sinon.stub(TaskManager.prototype, 'initQueue').resolves();
mainInstance.lastProcessedPosition = { blockNumber: 10, primaryKey: 1 };

await mainInstance.initWorker();
assert(mainInstance.handleInitPosition.calledOnce);
assert.strictEqual(mainInstance.taskManager.lastPushedToQueue, 0);
});

it('workLoop throws error when worker can\'t be initialised', async () => {
sinon.stub(BaseWorker.prototype, 'work').rejects(new Error('Error in worker "work" method'));
const mainInstance = new Main();
mainInstance.worker = new BaseWorker(constants);
mainInstance.taskManager = new TaskManager(0, 50);
await mainInstance.taskManager.initQueue(1);
try {
await mainInstance.workLoop();
expect.fail('workLoop should have thrown an error');
Expand Down

0 comments on commit 0739740

Please sign in to comment.