|
| 1 | +/*! |
| 2 | + * Additional RedisQueue tests: processCleanup connectedKeys filter branches |
| 3 | + */ |
| 4 | +import './mocks'; |
| 5 | +import { expect } from 'chai'; |
| 6 | +import * as sinon from 'sinon'; |
| 7 | +import { RedisQueue, uuid } from '../src'; |
| 8 | + |
| 9 | +describe('RedisQueue.processCleanup connectedKeys RX/filter combinations', function() { |
| 10 | + this.timeout(5000); |
| 11 | + |
| 12 | + it('should handle RX_CLIENT_TEST true but filter false case (exclude unmatched prefix)', async () => { |
| 13 | + const name = `PCleanRX_${uuid()}`; |
| 14 | + const rq: any = new RedisQueue(name, { |
| 15 | + logger: console, |
| 16 | + cleanup: true, |
| 17 | + prefix: 'imqA', |
| 18 | + cleanupFilter: '*', |
| 19 | + }); |
| 20 | + |
| 21 | + await rq.start(); |
| 22 | + |
| 23 | + const writer: any = rq.writer; |
| 24 | + |
| 25 | + // Stub client('LIST') to include a writer channel with a different prefix, |
| 26 | + // so RX_CLIENT_TEST.test(name) is true but filter.test(name) is false. |
| 27 | + const clientStub = sinon.stub(writer, 'client'); |
| 28 | + clientStub.callsFake(async (cmd: string) => { |
| 29 | + if (cmd === 'LIST') { |
| 30 | + return [ |
| 31 | + 'id=1 name=imqZ:Other:writer:pid:1:host:x', // RX true, filter false |
| 32 | + 'id=2 name=imqA:Other:subscription:pid:1:host:x', // RX false, filter true |
| 33 | + ].join('\n'); |
| 34 | + } |
| 35 | + return true as any; |
| 36 | + }); |
| 37 | + |
| 38 | + // Return no keys on SCAN to avoid deletions and just walk the branch |
| 39 | + const scanStub = sinon.stub(writer, 'scan'); |
| 40 | + scanStub.resolves(['0', []] as any); |
| 41 | + |
| 42 | + const delSpy = sinon.spy(writer, 'del'); |
| 43 | + |
| 44 | + await rq.processCleanup(); |
| 45 | + |
| 46 | + expect(delSpy.called).to.equal(false); |
| 47 | + |
| 48 | + clientStub.restore(); |
| 49 | + scanStub.restore(); |
| 50 | + delSpy.restore(); |
| 51 | + await rq.destroy(); |
| 52 | + }); |
| 53 | +}); |
0 commit comments