You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
* 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>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { strict as assert } from 'node:assert';
|
|
import testUtils, { GLOBAL } from '../test-utils';
|
|
import XAUTOCLAIM from './XAUTOCLAIM';
|
|
|
|
describe('XAUTOCLAIM', () => {
|
|
testUtils.isVersionGreaterThanHook([6, 2]);
|
|
|
|
describe('transformArguments', () => {
|
|
it('simple', () => {
|
|
assert.deepEqual(
|
|
XAUTOCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0'),
|
|
['XAUTOCLAIM', 'key', 'group', 'consumer', '1', '0-0']
|
|
);
|
|
});
|
|
|
|
it('with COUNT', () => {
|
|
assert.deepEqual(
|
|
XAUTOCLAIM.transformArguments('key', 'group', 'consumer', 1, '0-0', {
|
|
COUNT: 1
|
|
}),
|
|
['XAUTOCLAIM', 'key', 'group', 'consumer', '1', '0-0', 'COUNT', '1']
|
|
);
|
|
});
|
|
});
|
|
|
|
testUtils.testAll('xAutoClaim', async client => {
|
|
const message = Object.create(null, {
|
|
field: {
|
|
value: 'value',
|
|
enumerable: true
|
|
}
|
|
});
|
|
|
|
const [, id1, id2, , , reply] = await Promise.all([
|
|
client.xGroupCreate('key', 'group', '$', {
|
|
MKSTREAM: true
|
|
}),
|
|
client.xAdd('key', '*', message),
|
|
client.xAdd('key', '*', message),
|
|
client.xReadGroup('group', 'consumer', {
|
|
key: 'key',
|
|
id: '>'
|
|
}),
|
|
client.xTrim('key', 'MAXLEN', 1),
|
|
client.xAutoClaim('key', 'group', 'consumer', 0, '0-0')
|
|
]);
|
|
|
|
assert.deepEqual(reply, {
|
|
nextId: '0-0',
|
|
...(testUtils.isVersionGreaterThan([7, 0]) ? {
|
|
messages: [{
|
|
id: id2,
|
|
message
|
|
}],
|
|
deletedMessages: [id1]
|
|
} : {
|
|
messages: [null, {
|
|
id: id2,
|
|
message
|
|
}],
|
|
deletedMessages: undefined
|
|
})
|
|
});
|
|
}, {
|
|
client: GLOBAL.SERVERS.OPEN,
|
|
cluster: GLOBAL.CLUSTERS.OPEN
|
|
});
|
|
});
|