Skip to content

Commit 93fe2cb

Browse files
committed
feat: add more tests to improve coverage
1 parent b9f6a5a commit 93fe2cb

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*!
2+
* Additional RedisQueue tests: processDelayed() catch branch
3+
*/
4+
import './mocks';
5+
import { expect } from 'chai';
6+
import * as sinon from 'sinon';
7+
import { RedisQueue } from '../src';
8+
9+
function makeLogger() {
10+
return {
11+
log: (..._args: any[]) => undefined,
12+
info: (..._args: any[]) => undefined,
13+
warn: (..._args: any[]) => undefined,
14+
error: (..._args: any[]) => undefined,
15+
} as any;
16+
}
17+
18+
describe('RedisQueue.processDelayed extra branches', function() {
19+
this.timeout(10000);
20+
21+
it('should emit error when evalsha throws', async () => {
22+
const logger = makeLogger();
23+
const rq: any = new RedisQueue('ProcessDelayedCatch', { logger });
24+
await rq.start();
25+
26+
// Force checksum to exist to enter evalsha path
27+
rq.scripts.moveDelayed.checksum = 'deadbeef';
28+
29+
const err = new Error('evalsha failed');
30+
const emitErrorStub = sinon.stub((RedisQueue as any).prototype, 'emitError');
31+
32+
// Temporarily drop writer to force a synchronous error in processDelayed
33+
const originalWriter = rq.writer;
34+
rq['writer'] = undefined;
35+
36+
await rq['processDelayed'](rq.key);
37+
38+
expect(emitErrorStub.called).to.be.true;
39+
expect(emitErrorStub.firstCall.args[0]).to.equal('OnProcessDelayed');
40+
41+
// Restore writer and cleanup
42+
rq['writer'] = originalWriter;
43+
emitErrorStub.restore();
44+
await rq.destroy();
45+
});
46+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*!
2+
* Additional RedisQueue tests: send() extra branches
3+
*/
4+
import './mocks';
5+
import { expect } from 'chai';
6+
import * as sinon from 'sinon';
7+
import { RedisQueue, IMQMode } from '../src';
8+
import { logger as testLogger } from './mocks';
9+
10+
function makeLogger() {
11+
return {
12+
log: (..._args: any[]) => undefined,
13+
info: (..._args: any[]) => undefined,
14+
warn: (..._args: any[]) => undefined,
15+
error: (..._args: any[]) => undefined,
16+
} as any;
17+
}
18+
19+
describe('RedisQueue.send() extra branches', function() {
20+
this.timeout(10000);
21+
22+
it('should throw when writer is still uninitialized after start()', async () => {
23+
const logger = makeLogger();
24+
const rq: any = new RedisQueue('SendNoWriter', { logger }, IMQMode.PUBLISHER);
25+
// Force start to be a no-op so writer remains undefined
26+
const startStub = sinon.stub(rq, 'start').resolves(rq);
27+
28+
let thrown: any;
29+
try {
30+
await rq.send('AnyQueue', { test: true });
31+
} catch (err) {
32+
thrown = err;
33+
}
34+
35+
expect(thrown).to.be.instanceof(TypeError);
36+
expect(`${thrown}`).to.include('unable to initialize queue');
37+
38+
startStub.restore();
39+
await rq.destroy().catch(() => undefined);
40+
});
41+
});

0 commit comments

Comments
 (0)