ioredis-streams 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -3
- package/dist/redis-client.d.ts +1 -0
- package/dist/redis-client.js.map +1 -1
- package/dist/stream-consumer.d.ts +26 -0
- package/dist/stream-consumer.js +85 -2
- package/dist/stream-consumer.js.map +1 -1
- package/dist/types.d.ts +14 -1
- package/docs/api.md +395 -0
- package/docs/configuration.md +131 -0
- package/docs/dead-letters.md +132 -0
- package/docs/examples.md +339 -0
- package/package.json +2 -2
- package/src/redis-client.ts +3 -0
- package/src/stream-consumer.ts +85 -1
- package/src/types.ts +14 -1
- package/test/events.spec.ts +1 -1
- package/test/redis-streams.spec.ts +23 -3
- package/test/stream-consumer.integration.spec.ts +149 -0
- package/test/stream-consumer.spec.ts +206 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import 'mocha';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import Redis from 'ioredis';
|
|
4
|
+
import { StreamConsumer } from '../src/stream-consumer';
|
|
5
|
+
import { ConsumerConfigs } from '../src/types';
|
|
6
|
+
import { IRedisClient } from '../src/redis-client';
|
|
7
|
+
|
|
8
|
+
// Runs against a real Redis only when REDIS_IT_HOST is set, e.g.
|
|
9
|
+
// docker run --rm -d -p 6390:6379 redis:7 && REDIS_IT_HOST=localhost REDIS_IT_PORT=6390 npm test
|
|
10
|
+
const host = process.env.REDIS_IT_HOST;
|
|
11
|
+
const port = parseInt(process.env.REDIS_IT_PORT || '6379');
|
|
12
|
+
const describeIt = host ? describe : describe.skip;
|
|
13
|
+
|
|
14
|
+
const silent: any = { trace: () => {}, info: () => {}, warn: () => {}, error: () => {} };
|
|
15
|
+
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
|
|
16
|
+
|
|
17
|
+
async function until(cond: () => boolean | Promise<boolean>, timeout = 10000): Promise<void> {
|
|
18
|
+
const start = Date.now();
|
|
19
|
+
while (!(await cond())) {
|
|
20
|
+
if (Date.now() - start > timeout) throw new Error('Timed out waiting for condition');
|
|
21
|
+
await wait(50);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describeIt('StreamConsumer (integration, real Redis)', function () {
|
|
26
|
+
this.timeout(30000);
|
|
27
|
+
|
|
28
|
+
let admin: Redis.Redis;
|
|
29
|
+
const clients: Redis.Redis[] = [];
|
|
30
|
+
let stream: string;
|
|
31
|
+
const group = 'it-group';
|
|
32
|
+
|
|
33
|
+
const newClient = () => {
|
|
34
|
+
const c = new Redis({ host, port });
|
|
35
|
+
clients.push(c);
|
|
36
|
+
return c;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const makeConsumer = (
|
|
40
|
+
peerName: string,
|
|
41
|
+
handler: (id: string) => Promise<any>,
|
|
42
|
+
overrides: Partial<ConsumerConfigs> = {},
|
|
43
|
+
) => new StreamConsumer(newClient() as unknown as IRedisClient, async (id) => handler(id), {
|
|
44
|
+
streamName: stream,
|
|
45
|
+
groupName: group,
|
|
46
|
+
peerName,
|
|
47
|
+
batchSize: 5,
|
|
48
|
+
claimIdleTime: 300,
|
|
49
|
+
readBlockTime: 100,
|
|
50
|
+
mode: 'parallel',
|
|
51
|
+
maxLen: 1000,
|
|
52
|
+
logger: silent,
|
|
53
|
+
...overrides,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const consumerNames = async () =>
|
|
57
|
+
((await admin.xinfo('CONSUMERS', stream, group)) as any[]).map(c => c[1] as string);
|
|
58
|
+
|
|
59
|
+
beforeEach(async () => {
|
|
60
|
+
admin = newClient();
|
|
61
|
+
stream = `it-stream-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterEach(async () => {
|
|
65
|
+
await admin.del(stream);
|
|
66
|
+
clients.splice(0).forEach(c => c.disconnect());
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const pendingOf = async (consumer: string) =>
|
|
70
|
+
(await admin.xpending(stream, group, '-', '+', 100, consumer)) as [string, string, number, number][];
|
|
71
|
+
const payload = JSON.stringify({ name: 'evt', v: '1', time: 1, data: {} });
|
|
72
|
+
|
|
73
|
+
it('does not lose a failed message on stop: the consumer is kept and another consumer retries it', async () => {
|
|
74
|
+
const processedByB: string[] = [];
|
|
75
|
+
|
|
76
|
+
const a = makeConsumer('pod-a', async () => { throw new Error('handler failed'); });
|
|
77
|
+
await a.init();
|
|
78
|
+
a.start();
|
|
79
|
+
const id = await admin.xadd(stream, '*', 'evt', payload);
|
|
80
|
+
|
|
81
|
+
// pod-a read the message, its handler failed, so it stays pending on pod-a
|
|
82
|
+
await until(async () => (await pendingOf('pod-a')).length === 1);
|
|
83
|
+
await a.dispose();
|
|
84
|
+
|
|
85
|
+
// pod-a is kept, together with its pending message
|
|
86
|
+
expect(await consumerNames()).to.include('pod-a');
|
|
87
|
+
expect((await pendingOf('pod-a')).map(p => p[0])).to.deep.equal([id]);
|
|
88
|
+
|
|
89
|
+
const b = makeConsumer('pod-b', async (msgId) => { processedByB.push(msgId); });
|
|
90
|
+
await b.init();
|
|
91
|
+
b.start();
|
|
92
|
+
await until(() => processedByB.length > 0);
|
|
93
|
+
await b.dispose();
|
|
94
|
+
|
|
95
|
+
expect(processedByB).to.deep.equal([id]);
|
|
96
|
+
expect(((await admin.xpending(stream, group)) as any[])[0]).to.equal(0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('periodic cleanup removes idle consumers with nothing pending and keeps those with pending messages', async () => {
|
|
100
|
+
const reader = newClient();
|
|
101
|
+
await admin.xgroup('CREATE', stream, group, '$', 'MKSTREAM');
|
|
102
|
+
const id1 = await admin.xadd(stream, '*', 'evt', payload);
|
|
103
|
+
await admin.xadd(stream, '*', 'evt', payload);
|
|
104
|
+
// two "killed" consumers: one holding a pending message, one with nothing pending
|
|
105
|
+
await reader.xreadgroup('GROUP', group, 'killed-with-pending', 'COUNT', 1, 'STREAMS', stream, '>');
|
|
106
|
+
const read = await reader.xreadgroup('GROUP', group, 'killed-empty', 'COUNT', 1, 'STREAMS', stream, '>') as any;
|
|
107
|
+
await reader.xack(stream, group, read[0][1][0][0]);
|
|
108
|
+
|
|
109
|
+
// idle floor = 2 * (readBlockTime + claimIdleTime) = 2 * (100 + 300) = 800ms
|
|
110
|
+
await wait(1000);
|
|
111
|
+
const b = makeConsumer('pod-b', async () => undefined, {
|
|
112
|
+
deadConsumerIdleTime: 1,
|
|
113
|
+
deadConsumerCheckInterval: 100000,
|
|
114
|
+
});
|
|
115
|
+
b.lastTimePendingCheck = Date.now() + 60000; // keep pod-b from claiming, to observe the cleanup alone
|
|
116
|
+
await b.init();
|
|
117
|
+
b.start();
|
|
118
|
+
await until(async () => !(await consumerNames()).includes('killed-empty'), 5000);
|
|
119
|
+
await b.dispose();
|
|
120
|
+
|
|
121
|
+
const names = await consumerNames();
|
|
122
|
+
expect(names).to.not.include('killed-empty');
|
|
123
|
+
expect(names).to.include('killed-with-pending');
|
|
124
|
+
expect((await pendingOf('killed-with-pending')).map(p => p[0])).to.deep.equal([id1]);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('cleanup runs on stop and removes consumers that became idle and empty', async () => {
|
|
128
|
+
const processed: string[] = [];
|
|
129
|
+
const a = makeConsumer('pod-a', async (msgId) => { processed.push(msgId); });
|
|
130
|
+
await a.init();
|
|
131
|
+
a.start();
|
|
132
|
+
await admin.xadd(stream, '*', 'evt', payload);
|
|
133
|
+
await until(() => processed.length === 1);
|
|
134
|
+
await a.dispose();
|
|
135
|
+
expect(await consumerNames()).to.include('pod-a');
|
|
136
|
+
|
|
137
|
+
// pod-b only checks on startup and on stop (huge interval); idle floor = 2 * (100 + 300) = 800ms
|
|
138
|
+
const b = makeConsumer('pod-b', async () => undefined, {
|
|
139
|
+
deadConsumerIdleTime: 1,
|
|
140
|
+
deadConsumerCheckInterval: 100000000,
|
|
141
|
+
});
|
|
142
|
+
await b.init();
|
|
143
|
+
b.start();
|
|
144
|
+
await wait(1000);
|
|
145
|
+
expect(await consumerNames()).to.include('pod-a');
|
|
146
|
+
await b.dispose();
|
|
147
|
+
expect(await consumerNames()).to.not.include('pod-a');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import 'mocha';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
|
-
import
|
|
3
|
+
import sinon from 'sinon';
|
|
4
|
+
import {
|
|
5
|
+
StreamConsumer, EventProcessor, DEFAULT_DEAD_CONSUMER_IDLE_TIME, DEFAULT_DEAD_CONSUMER_CHECK_INTERVAL,
|
|
6
|
+
} from '../src/stream-consumer';
|
|
4
7
|
import { ConsumerConfigs, IEvent, IWaitEvent } from '../src/types';
|
|
5
8
|
import { createFakeRedis, FakeRedis } from './helpers/fake-redis';
|
|
6
9
|
|
|
@@ -17,6 +20,16 @@ class T extends StreamConsumer {
|
|
|
17
20
|
async testDoRead() { return this.doRead(); }
|
|
18
21
|
async testProcessMessage(id: string, message: string[]) { return this.processMessage(id, message); }
|
|
19
22
|
async testTryReading() { return this.tryReading(); }
|
|
23
|
+
async testCleanupDeadConsumers() { return this.cleanupDeadConsumers(); }
|
|
24
|
+
get testLastTimeConsumersCleanup() { return this.lastTimeConsumersCleanup; }
|
|
25
|
+
set testLastTimeConsumersCleanup(v: number) { this.lastTimeConsumersCleanup = v; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function makeLogger() {
|
|
29
|
+
const calls: Record<string, any[][]> = { trace: [], info: [], warn: [], error: [] };
|
|
30
|
+
const logger: any = {};
|
|
31
|
+
for (const level of Object.keys(calls)) logger[level] = (...args: any[]) => { calls[level].push(args); };
|
|
32
|
+
return { logger, calls };
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
function makeConfig(overrides: Partial<ConsumerConfigs> = {}): ConsumerConfigs {
|
|
@@ -416,6 +429,9 @@ describe('StreamConsumer', () => {
|
|
|
416
429
|
});
|
|
417
430
|
|
|
418
431
|
describe('dispose()', () => {
|
|
432
|
+
const HOUR = 60 * 60 * 1000;
|
|
433
|
+
const flat = (name: string, pending: number, idle: number) => ['name', name, 'pending', pending, 'idle', idle];
|
|
434
|
+
|
|
419
435
|
it('sets the disposing flag to stop the reading loop', async () => {
|
|
420
436
|
const fake = createFakeRedis();
|
|
421
437
|
const consumer = new T(fake, async () => undefined, makeConfig());
|
|
@@ -423,6 +439,195 @@ describe('StreamConsumer', () => {
|
|
|
423
439
|
await consumer.dispose();
|
|
424
440
|
expect(consumer.testDisposing).to.be.true;
|
|
425
441
|
});
|
|
442
|
+
|
|
443
|
+
it('does not remove itself from the group, so its pending messages stay retryable', async () => {
|
|
444
|
+
const fake: any = createFakeRedis();
|
|
445
|
+
fake.xinfo = sinon.stub().resolves([flat('peer-1', 2, 25 * HOUR)]);
|
|
446
|
+
const consumer = new T(fake, async () => undefined, makeConfig());
|
|
447
|
+
await consumer.dispose();
|
|
448
|
+
expect(fake.xgroup.calledWith('DELCONSUMER', 'my-stream', 'my-group', 'peer-1')).to.be.false;
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it('runs the dead-consumer cleanup on stop, even right after a periodic run', async () => {
|
|
452
|
+
const fake: any = createFakeRedis();
|
|
453
|
+
fake.xinfo = sinon.stub().resolves([flat('dead', 0, 25 * HOUR)]);
|
|
454
|
+
const consumer = new T(fake, async () => undefined, makeConfig());
|
|
455
|
+
consumer.testLastTimeConsumersCleanup = Date.now();
|
|
456
|
+
await consumer.dispose();
|
|
457
|
+
expect(fake.xinfo.calledOnce).to.be.true;
|
|
458
|
+
expect(fake.xgroup.calledWith('DELCONSUMER', 'my-stream', 'my-group', 'dead')).to.be.true;
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('runs the cleanup on stop even when the periodic run is disabled', async () => {
|
|
462
|
+
const fake: any = createFakeRedis();
|
|
463
|
+
fake.xinfo = sinon.stub().resolves([]);
|
|
464
|
+
const consumer = new T(fake, async () => undefined, makeConfig({ deadConsumerCheckInterval: 0 }));
|
|
465
|
+
await consumer.dispose();
|
|
466
|
+
expect(fake.xinfo.calledOnce).to.be.true;
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it('waits for the in-flight reading loop to finish before running the cleanup', async () => {
|
|
470
|
+
const fake: any = createFakeRedis();
|
|
471
|
+
fake.xinfo = sinon.stub().resolves([]);
|
|
472
|
+
let unblock!: () => void;
|
|
473
|
+
fake.xreadgroup.callsFake(async () => {
|
|
474
|
+
await new Promise<void>(r => { unblock = r; });
|
|
475
|
+
return null;
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
const consumer = new T(fake, async () => undefined, makeConfig());
|
|
479
|
+
consumer.lastTimePendingCheck = Date.now(); // skip claim
|
|
480
|
+
consumer.testLastTimeConsumersCleanup = Date.now(); // skip periodic cleanup
|
|
481
|
+
|
|
482
|
+
const started = consumer.start();
|
|
483
|
+
await new Promise(r => setTimeout(r, 0));
|
|
484
|
+
|
|
485
|
+
const disposing = consumer.dispose();
|
|
486
|
+
await new Promise(r => setTimeout(r, 0));
|
|
487
|
+
expect(fake.xinfo.called).to.be.false;
|
|
488
|
+
|
|
489
|
+
unblock();
|
|
490
|
+
await started;
|
|
491
|
+
await disposing;
|
|
492
|
+
expect(fake.xinfo.calledOnce).to.be.true;
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it('never throws when the cleanup fails', async () => {
|
|
496
|
+
const fake: any = createFakeRedis();
|
|
497
|
+
fake.xinfo = sinon.stub().rejects(new Error('connection closed'));
|
|
498
|
+
const consumer = new T(fake, async () => undefined, makeConfig());
|
|
499
|
+
await expect(consumer.dispose()).to.eventually.not.be.rejected;
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
describe('cleanupDeadConsumers()', () => {
|
|
504
|
+
const HOUR = 60 * 60 * 1000;
|
|
505
|
+
const flat = (name: string, pending: number, idle: number) => ['name', name, 'pending', pending, 'idle', idle];
|
|
506
|
+
|
|
507
|
+
function setup(consumers: any[], overrides: Partial<ConsumerConfigs> = {}) {
|
|
508
|
+
const fake: any = createFakeRedis();
|
|
509
|
+
fake.xinfo = sinon.stub().resolves(consumers);
|
|
510
|
+
const { logger, calls } = makeLogger();
|
|
511
|
+
const consumer = new T(fake, async () => undefined, makeConfig({ logger, ...overrides }));
|
|
512
|
+
return { fake, consumer, calls };
|
|
513
|
+
}
|
|
514
|
+
const deleted = (fake: any) => fake.xgroup.getCalls()
|
|
515
|
+
.filter((c: any) => c.args[0] === 'DELCONSUMER').map((c: any) => c.args[3]);
|
|
516
|
+
|
|
517
|
+
it('defaults to removing consumers idle for 24h, checked every 6h', () => {
|
|
518
|
+
expect(DEFAULT_DEAD_CONSUMER_IDLE_TIME).to.equal(24 * HOUR);
|
|
519
|
+
expect(DEFAULT_DEAD_CONSUMER_CHECK_INTERVAL).to.equal(6 * HOUR);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it('removes only consumers idle beyond 24h with no pending messages, never itself', async () => {
|
|
523
|
+
const { fake, consumer } = setup([
|
|
524
|
+
flat('dead', 0, 25 * HOUR),
|
|
525
|
+
flat('dead-with-pending', 3, 25 * HOUR),
|
|
526
|
+
flat('recent', 0, 2 * HOUR),
|
|
527
|
+
flat('alive', 0, 1000),
|
|
528
|
+
flat('peer-1', 0, 25 * HOUR),
|
|
529
|
+
]);
|
|
530
|
+
await consumer.testCleanupDeadConsumers();
|
|
531
|
+
expect(fake.xinfo.calledWith('CONSUMERS', 'my-stream', 'my-group')).to.be.true;
|
|
532
|
+
expect(deleted(fake)).to.deep.equal(['dead']);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('re-checks the pending entries of the consumer right before DELCONSUMER', async () => {
|
|
536
|
+
const { fake, consumer } = setup([flat('dead', 0, 25 * HOUR)]);
|
|
537
|
+
await consumer.testCleanupDeadConsumers();
|
|
538
|
+
expect(fake.xpending.calledWith('my-stream', 'my-group', '-', '+', 1, 'dead')).to.be.true;
|
|
539
|
+
expect(fake.xpending.calledBefore(fake.xgroup)).to.be.true;
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it('keeps the consumer when the re-check finds pending messages', async () => {
|
|
543
|
+
const { fake, consumer, calls } = setup([flat('dead', 0, 25 * HOUR)]);
|
|
544
|
+
fake.xpending.withArgs('my-stream', 'my-group', '-', '+', 1, 'dead').resolves([['1-0', 'dead', 10, 1]]);
|
|
545
|
+
await consumer.testCleanupDeadConsumers();
|
|
546
|
+
expect(deleted(fake)).to.deep.equal([]);
|
|
547
|
+
expect(calls.info).to.have.length(0);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it('warns with the count when DELCONSUMER reports discarded pending messages', async () => {
|
|
551
|
+
const { fake, consumer, calls } = setup([flat('dead', 0, 25 * HOUR)]);
|
|
552
|
+
fake.xgroup.withArgs('DELCONSUMER').resolves(2);
|
|
553
|
+
await consumer.testCleanupDeadConsumers();
|
|
554
|
+
expect(calls.warn.some(args => /discarded 2 pending/.test(args[0]))).to.be.true;
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('accepts object-shaped XINFO entries', async () => {
|
|
558
|
+
const { fake, consumer } = setup([{ name: 'dead', pending: 0, idle: 25 * HOUR }]);
|
|
559
|
+
await consumer.testCleanupDeadConsumers();
|
|
560
|
+
expect(deleted(fake)).to.deep.equal(['dead']);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
it('honours a custom deadConsumerIdleTime', async () => {
|
|
564
|
+
const { fake, consumer } = setup([flat('a', 0, 3 * HOUR), flat('b', 0, HOUR)], { deadConsumerIdleTime: 2 * HOUR });
|
|
565
|
+
await consumer.testCleanupDeadConsumers();
|
|
566
|
+
expect(deleted(fake)).to.deep.equal(['a']);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
it('raises a too-low idle threshold to 2 x (readBlockTime + claimIdleTime)', async () => {
|
|
570
|
+
// floor = 2 * (5000 + 15000) = 40000
|
|
571
|
+
const { fake, consumer } = setup([flat('a', 0, 30000), flat('b', 0, 50000)], { deadConsumerIdleTime: 1 });
|
|
572
|
+
await consumer.testCleanupDeadConsumers();
|
|
573
|
+
expect(deleted(fake)).to.deep.equal(['b']);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it('is disabled entirely when deadConsumerIdleTime is 0', async () => {
|
|
577
|
+
const { fake, consumer } = setup([flat('a', 0, 25 * HOUR)], { deadConsumerIdleTime: 0 });
|
|
578
|
+
await consumer.testCleanupDeadConsumers();
|
|
579
|
+
await consumer.dispose();
|
|
580
|
+
expect(fake.xinfo.called).to.be.false;
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it('is skipped when the client has no xinfo', async () => {
|
|
584
|
+
const fake = createFakeRedis();
|
|
585
|
+
const consumer = new T(fake, async () => undefined, makeConfig());
|
|
586
|
+
await expect(consumer.testCleanupDeadConsumers()).to.eventually.not.be.rejected;
|
|
587
|
+
expect(fake.xgroup.called).to.be.false;
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it('runs at most once every 6 hours by default', async () => {
|
|
591
|
+
const { fake, consumer } = setup([]);
|
|
592
|
+
await consumer.testCleanupDeadConsumers();
|
|
593
|
+
await consumer.testCleanupDeadConsumers();
|
|
594
|
+
expect(fake.xinfo.calledOnce).to.be.true;
|
|
595
|
+
consumer.testLastTimeConsumersCleanup = Date.now() - 5 * HOUR;
|
|
596
|
+
await consumer.testCleanupDeadConsumers();
|
|
597
|
+
expect(fake.xinfo.calledOnce).to.be.true;
|
|
598
|
+
consumer.testLastTimeConsumersCleanup = Date.now() - 6 * HOUR - 1;
|
|
599
|
+
await consumer.testCleanupDeadConsumers();
|
|
600
|
+
expect(fake.xinfo.calledTwice).to.be.true;
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it('honours a custom deadConsumerCheckInterval', async () => {
|
|
604
|
+
const { fake, consumer } = setup([], { deadConsumerCheckInterval: 60 * 1000 });
|
|
605
|
+
await consumer.testCleanupDeadConsumers();
|
|
606
|
+
consumer.testLastTimeConsumersCleanup = Date.now() - 61 * 1000;
|
|
607
|
+
await consumer.testCleanupDeadConsumers();
|
|
608
|
+
expect(fake.xinfo.calledTwice).to.be.true;
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('does not run periodically when deadConsumerCheckInterval is 0', async () => {
|
|
612
|
+
const { fake, consumer } = setup([], { deadConsumerCheckInterval: 0 });
|
|
613
|
+
await consumer.testCleanupDeadConsumers();
|
|
614
|
+
expect(fake.xinfo.called).to.be.false;
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
it('logs and swallows errors', async () => {
|
|
618
|
+
const { fake, consumer, calls } = setup([]);
|
|
619
|
+
fake.xinfo.rejects(new Error('NOGROUP'));
|
|
620
|
+
await expect(consumer.testCleanupDeadConsumers()).to.eventually.not.be.rejected;
|
|
621
|
+
expect(calls.warn).to.have.length(1);
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it('runs from the reading loop on startup', async () => {
|
|
625
|
+
const { fake, consumer } = setup([]);
|
|
626
|
+
consumer.lastTimePendingCheck = Date.now();
|
|
627
|
+
fake.xreadgroup.callsFake(async () => { consumer.testDisposing = true; return null; });
|
|
628
|
+
await consumer.testTryReading();
|
|
629
|
+
expect(fake.xinfo.calledOnce).to.be.true;
|
|
630
|
+
});
|
|
426
631
|
});
|
|
427
632
|
|
|
428
633
|
describe('publishDeadLetters()', () => {
|