Skip to content

Commit 8a8bec6

Browse files
committed
fix(client): Fix race condition in specs
1 parent eb2c37e commit 8a8bec6

File tree

4 files changed

+28
-47
lines changed

4 files changed

+28
-47
lines changed

packages/client/lib/commands/XAUTOCLAIM.spec.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ describe('XAUTOCLAIM', () => {
2525

2626
testUtils.testWithClient('client.xAutoClaim without messages', async client => {
2727
await Promise.all([
28-
client.xGroupCreate('key', 'group', '$', {
29-
MKSTREAM: true
30-
}),
28+
client.xGroupCreate('key', 'group', '$', { MKSTREAM: true }),
3129
client.xGroupCreateConsumer('key', 'group', 'consumer'),
3230
]);
3331

@@ -41,17 +39,13 @@ describe('XAUTOCLAIM', () => {
4139
}, GLOBAL.SERVERS.OPEN);
4240

4341
testUtils.testWithClient('client.xAutoClaim with messages', async client => {
44-
const [,,id,] = await Promise.all([
45-
client.xGroupCreate('key', 'group', '$', {
46-
MKSTREAM: true
47-
}),
48-
client.xGroupCreateConsumer('key', 'group', 'consumer'),
49-
client.xAdd('key', '*', { foo: 'bar' }),
50-
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' })
51-
]);
42+
await client.xGroupCreate('key', 'group', '$', { MKSTREAM: true });
43+
await client.xGroupCreateConsumer('key', 'group', 'consumer');
44+
const id = await client.xAdd('key', '*', { foo: 'bar' });
45+
await client.xReadGroup('group', 'consumer', { key: 'key', id: '>' });
5246

5347
assert.deepEqual(
54-
await client.xAutoClaim('key', 'group', 'consumer', 1, '0-0'),
48+
await client.xAutoClaim('key', 'group', 'consumer', 0, '0-0'),
5549
{
5650
nextId: '0-0',
5751
messages: [{
@@ -67,31 +61,27 @@ describe('XAUTOCLAIM', () => {
6761
}, GLOBAL.SERVERS.OPEN);
6862

6963
testUtils.testWithClient('client.xAutoClaim with trimmed messages', async client => {
70-
const [,,,,,id2,] = await Promise.all([
71-
client.xGroupCreate('key', 'group', '$', {
72-
MKSTREAM: true
73-
}),
74-
client.xGroupCreateConsumer('key', 'group', 'consumer'),
75-
client.xAdd('key', '*', { foo: 'bar' }),
76-
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' }),
77-
client.xTrim('key', 'MAXLEN', 0),
78-
client.xAdd('key', '*', { bar: 'baz' }),
79-
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' }),
80-
]);
64+
await client.xGroupCreate('key', 'group', '$', { MKSTREAM: true });
65+
await client.xGroupCreateConsumer('key', 'group', 'consumer');
66+
await client.xAdd('key', '*', { foo: 'bar' });
67+
await client.xReadGroup('group', 'consumer', { key: 'key', id: '>' });
68+
await client.xTrim('key', 'MAXLEN', 0);
69+
const id = await client.xAdd('key', '*', { bar: 'baz' });
70+
await client.xReadGroup('group', 'consumer', { key: 'key', id: '>' });
8171

8272
assert.deepEqual(
83-
await client.xAutoClaim('key', 'group', 'consumer', 1, '0-0'),
73+
await client.xAutoClaim('key', 'group', 'consumer', 0, '0-0'),
8474
{
8575
nextId: '0-0',
8676
messages: testUtils.isVersionGreaterThan([7, 0]) ? [{
87-
id: id2,
77+
id,
8878
message: Object.create(null, { 'bar': {
8979
value: 'baz',
9080
configurable: true,
9181
enumerable: true
9282
} })
9383
}] : [null, {
94-
id: id2,
84+
id,
9585
message: Object.create(null, { 'bar': {
9686
value: 'baz',
9787
configurable: true,

packages/client/lib/commands/XCLAIM.spec.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,18 @@ describe('XCLAIM', () => {
8383
});
8484

8585
assert.deepEqual(
86-
await client.xClaim('key', 'group', 'consumer', 1, '0-0'),
86+
await client.xClaim('key', 'group', 'consumer', 0, '0-0'),
8787
[]
8888
);
8989
}, GLOBAL.SERVERS.OPEN);
9090

9191
testUtils.testWithClient('client.xClaim with a message', async client => {
92-
const [,,id,] = await Promise.all([
93-
client.xGroupCreate('key', 'group', '$', {
94-
MKSTREAM: true
95-
}),
96-
client.xGroupCreateConsumer('key', 'group', 'consumer'),
97-
client.xAdd('key', '*', { foo: 'bar' }),
98-
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' })
99-
]);
92+
await client.xGroupCreate('key', 'group', '$', { MKSTREAM: true });
93+
const id = await client.xAdd('key', '*', { foo: 'bar' });
94+
await client.xReadGroup('group', 'consumer', { key: 'key', id: '>' });
10095

10196
assert.deepEqual(
102-
await client.xClaim('key', 'group', 'consumer', 1, id),
97+
await client.xClaim('key', 'group', 'consumer', 0, id),
10398
[{
10499
id,
105100
message: Object.create(null, { 'foo': {
@@ -112,18 +107,13 @@ describe('XCLAIM', () => {
112107
}, GLOBAL.SERVERS.OPEN);
113108

114109
testUtils.testWithClient('client.xClaim with a trimmed message', async client => {
115-
const [,,id,,,] = await Promise.all([
116-
client.xGroupCreate('key', 'group', '$', {
117-
MKSTREAM: true
118-
}),
119-
client.xGroupCreateConsumer('key', 'group', 'consumer'),
120-
client.xAdd('key', '*', { foo: 'bar' }),
121-
client.xReadGroup('group', 'consumer', { key: 'key', id: '>' }),
122-
client.xTrim('key', 'MAXLEN', 0),
123-
]);
110+
await client.xGroupCreate('key', 'group', '$', { MKSTREAM: true });
111+
const id = await client.xAdd('key', '*', { foo: 'bar' });
112+
await client.xReadGroup('group', 'consumer', { key: 'key', id: '>' });
113+
await client.xTrim('key', 'MAXLEN', 0);
124114

125115
assert.deepEqual(
126-
await client.xClaim('key', 'group', 'consumer', 1, id),
116+
await client.xClaim('key', 'group', 'consumer', 0, id),
127117
testUtils.isVersionGreaterThan([7, 0]) ? []: [null]
128118
);
129119
}, GLOBAL.SERVERS.OPEN);

packages/test-utils/lib/dockers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface ErrorWithCode extends Error {
1414

1515
async function isPortAvailable(port: number): Promise<boolean> {
1616
try {
17-
const socket = createConnection({ port });
17+
const socket = createConnection({ host: '0.0.0.0', port });
1818
await once(socket, 'connect');
1919
socket.end();
2020
} catch (err) {

packages/test-utils/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export default class TestUtils {
136136

137137
const client = RedisClient.create({
138138
...options?.clientOptions,
139+
url: 'redis://0.0.0.0',
139140
socket: {
140141
...options?.clientOptions?.socket,
141142
port: (await dockerPromise).port

0 commit comments

Comments
 (0)