|
| 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 | +}); |
0 commit comments