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: 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>
This commit is contained in:
@@ -23,20 +23,76 @@ describe('XAUTOCLAIM', () => {
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testWithClient('client.xAutoClaim', async client => {
|
||||
await Promise.all([
|
||||
client.xGroupCreate('key', 'group', '$', {
|
||||
MKSTREAM: true
|
||||
}),
|
||||
testUtils.testWithClient('client.xAutoClaim without messages', async client => {
|
||||
const [,, reply] = await Promise.all([
|
||||
client.xGroupCreate('key', 'group', '$', { MKSTREAM: true }),
|
||||
client.xGroupCreateConsumer('key', 'group', 'consumer'),
|
||||
client.xAutoClaim('key', 'group', 'consumer', 1, '0-0')
|
||||
]);
|
||||
|
||||
assert.deepEqual(
|
||||
await client.xAutoClaim('key', 'group', 'consumer', 1, '0-0'),
|
||||
{
|
||||
nextId: '0-0',
|
||||
messages: []
|
||||
}
|
||||
);
|
||||
assert.deepEqual(reply, {
|
||||
nextId: '0-0',
|
||||
messages: []
|
||||
});
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithClient('client.xAutoClaim with messages', async client => {
|
||||
const [,, id,, reply] = await Promise.all([
|
||||
client.xGroupCreate('key', 'group', '$', { MKSTREAM: true }),
|
||||
client.xGroupCreateConsumer('key', 'group', 'consumer'),
|
||||
client.xAdd('key', '*', { foo: 'bar' }),
|
||||
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' }),
|
||||
client.xAutoClaim('key', 'group', 'consumer', 0, '0-0')
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, {
|
||||
nextId: '0-0',
|
||||
messages: [{
|
||||
id,
|
||||
message: Object.create(null, {
|
||||
foo: {
|
||||
value: 'bar',
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
}
|
||||
})
|
||||
}]
|
||||
});
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
|
||||
testUtils.testWithClient('client.xAutoClaim with trimmed messages', async client => {
|
||||
const [,,,,, id,, reply] = await Promise.all([
|
||||
client.xGroupCreate('key', 'group', '$', { MKSTREAM: true }),
|
||||
client.xGroupCreateConsumer('key', 'group', 'consumer'),
|
||||
client.xAdd('key', '*', { foo: 'bar' }),
|
||||
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' }),
|
||||
client.xTrim('key', 'MAXLEN', 0),
|
||||
client.xAdd('key', '*', { bar: 'baz' }),
|
||||
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' }),
|
||||
client.xAutoClaim('key', 'group', 'consumer', 0, '0-0')
|
||||
]);
|
||||
|
||||
assert.deepEqual(reply, {
|
||||
nextId: '0-0',
|
||||
messages: testUtils.isVersionGreaterThan([7, 0]) ? [{
|
||||
id,
|
||||
message: Object.create(null, {
|
||||
bar: {
|
||||
value: 'baz',
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
}
|
||||
})
|
||||
}] : [null, {
|
||||
id,
|
||||
message: Object.create(null, {
|
||||
bar: {
|
||||
value: 'baz',
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
}
|
||||
})
|
||||
}]
|
||||
});
|
||||
}, GLOBAL.SERVERS.OPEN);
|
||||
});
|
||||
|
Reference in New Issue
Block a user