1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00
Files
node-redis/packages/client/lib/commands/XCLAIM.spec.ts
Charley DAVID e00041e0eb Fix: XAUTOCLAIM after a TRIM with pending messages returns nil (#2565)
* fix(client): XCLAIM & XAUTOCLAIM after a TRIM might return nils

* fix(client): Fix race condition in specs

* revert test utils changes

* make tests faster

---------

Co-authored-by: Leibale Eidelman <me@leibale.com>
2023-09-19 17:37:16 -04:00

126 lines
3.5 KiB
TypeScript

import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import XCLAIM from './XCLAIM';
describe('XCLAIM', () => {
describe('transformArguments', () => {
it('single id (string)', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0'),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0']
);
});
it('multiple ids (array)', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, ['0-0', '1-0']),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', '1-0']
);
});
it('with IDLE', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
IDLE: 1
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'IDLE', '1']
);
});
describe('with TIME', () => {
it('number', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
TIME: 1
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'TIME', '1']
);
});
it('Date', () => {
const d = new Date();
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
TIME: d
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'TIME', d.getTime().toString()]
);
});
});
it('with RETRYCOUNT', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
RETRYCOUNT: 1
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'RETRYCOUNT', '1']
);
});
it('with FORCE', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
FORCE: true
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'FORCE']
);
});
it('with LASTID', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
LASTID: '0-0'
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'LASTID', '0-0']
);
});
it('with IDLE, TIME, RETRYCOUNT, FORCE, LASTID', () => {
assert.deepEqual(
XCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
IDLE: 1,
TIME: 1,
RETRYCOUNT: 1,
FORCE: true,
LASTID: '0-0'
}),
['XCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'IDLE', '1', 'TIME', '1', 'RETRYCOUNT', '1', 'FORCE', 'LASTID', '0-0']
);
});
});
testUtils.testAll('xClaim', async client => {
const message = Object.create(null, {
field: {
value: 'value',
enumerable: true
}
});
const [, , , , , reply] = await Promise.all([
client.xGroupCreate('key', 'group', '$', {
MKSTREAM: true
}),
client.xAdd('key', '1-0', message),
client.xAdd('key', '2-0', message),
client.xReadGroup('group', 'consumer', {
key: 'key',
id: '>'
}),
client.xTrim('key', 'MAXLEN', 1),
client.xClaim('key', 'group', 'consumer', 0, ['1-0', '2-0'])
]);
assert.deepEqual(reply, [
...(testUtils.isVersionGreaterThan([7, 0]) ? [] : [null]),
{
id: '2-0',
message
}
]);
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});