1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-17 19:41:06 +03:00

Do not use "timers/promises", fix "isRedisVersionGreaterThan"

This commit is contained in:
leibale
2021-07-12 19:04:14 -04:00
parent ad545b8230
commit b6629645cf
7 changed files with 22 additions and 18 deletions

View File

@@ -371,6 +371,9 @@ describe('Client', () => {
(await client.clientInfo()).db, (await client.clientInfo()).db,
1 1
); );
}, {
// because of CLIENT INFO
minimumRedisVersion: [6, 2]
}); });
itWithClient(TestRedisServers.OPEN, 'scanIterator', async client => { itWithClient(TestRedisServers.OPEN, 'scanIterator', async client => {

View File

@@ -1,8 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient } from '../test-utils'; import { TestRedisServers, itWithClient, describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './SMISMEMBER'; import { transformArguments } from './SMISMEMBER';
describe('SMISMEMBER', () => { describe('SMISMEMBER', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', ['1', '2']), transformArguments('key', ['1', '2']),

View File

@@ -78,12 +78,9 @@ describe('XCLAIM', () => {
}); });
itWithClient(TestRedisServers.OPEN, 'client.xClaim', async client => { itWithClient(TestRedisServers.OPEN, 'client.xClaim', async client => {
await Promise.all([ await client.xGroupCreate('key', 'group', '$', {
client.xGroupCreate('key', 'group', '$', { MKSTREAM: true
MKSTREAM: true });
}),
client.xGroupCreateConsumer('key', 'group', 'consumer'),
]);
assert.deepEqual( assert.deepEqual(
await client.xClaim('key', 'group', 'consumer', 1, '0-0'), await client.xClaim('key', 'group', 'consumer', 1, '0-0'),

View File

@@ -11,12 +11,9 @@ describe('XCLAIM JUSTID', () => {
}); });
itWithClient(TestRedisServers.OPEN, 'client.xClaimJustId', async client => { itWithClient(TestRedisServers.OPEN, 'client.xClaimJustId', async client => {
await Promise.all([ await client.xGroupCreate('key', 'group', '$', {
client.xGroupCreate('key', 'group', '$', { MKSTREAM: true
MKSTREAM: true });
}),
client.xGroupCreateConsumer('key', 'group', 'consumer'),
]);
assert.deepEqual( assert.deepEqual(
await client.xClaimJustId('key', 'group', 'consumer', 1, '0-0'), await client.xClaimJustId('key', 'group', 'consumer', 1, '0-0'),

View File

@@ -1,8 +1,8 @@
import EventEmitter from 'events'; import EventEmitter from 'events';
import net from 'net'; import net from 'net';
import tls from 'tls'; import tls from 'tls';
import { setTimeout } from 'timers/promises';
import { URL } from 'url'; import { URL } from 'url';
import { promiseTimeout } from './utils';
interface RedisSocketCommonOptions { interface RedisSocketCommonOptions {
username?: string; username?: string;
@@ -147,7 +147,7 @@ export default class RedisSocket extends EventEmitter {
throw retryIn; throw retryIn;
} }
await setTimeout(retryIn); await promiseTimeout(retryIn);
return this.#retryConnection(retries + 1); return this.#retryConnection(retries + 1);
} }
} }

View File

@@ -7,10 +7,10 @@ import { once } from 'events';
import { RedisSocketOptions } from './socket'; import { RedisSocketOptions } from './socket';
import which from 'which'; import which from 'which';
import { SinonSpy } from 'sinon'; import { SinonSpy } from 'sinon';
import { setTimeout } from 'timers/promises';
import RedisCluster, { RedisClusterType } from './cluster'; import RedisCluster, { RedisClusterType } from './cluster';
import { unlink } from 'fs/promises'; import { unlink } from 'fs/promises';
import { Context as MochaContext } from 'mocha'; import { Context as MochaContext } from 'mocha';
import { promiseTimeout } from './utils';
type RedisVersion = [major: number, minor: number, patch: number]; type RedisVersion = [major: number, minor: number, patch: number];
@@ -41,6 +41,8 @@ export function isRedisVersionGreaterThan(minimumVersion: PartialRedisVersion |
for (let i = 0; i < lastIndex; i++) { for (let i = 0; i < lastIndex; i++) {
if (REDIS_VERSION[i] > minimumVersion[i]) { if (REDIS_VERSION[i] > minimumVersion[i]) {
return true; return true;
} else if (minimumVersion[i] > REDIS_VERSION[i]) {
return false;
} }
} }
@@ -195,7 +197,7 @@ export async function spawnRedisCluster(type: TestRedisClusters | null, numberOf
} }
while ((await spawnResults[0].client.clusterInfo()).state !== 'ok') { while ((await spawnResults[0].client.clusterInfo()).state !== 'ok') {
await setTimeout(CLUSTER_NODE_TIMEOUT); await promiseTimeout(CLUSTER_NODE_TIMEOUT);
} }
const disconnectPromises = []; const disconnectPromises = [];
@@ -360,6 +362,6 @@ export async function waitTillBeenCalled(spy: SinonSpy): Promise<void> {
throw new Error('Waiting for more than 1 second'); throw new Error('Waiting for more than 1 second');
} }
await setTimeout(1); await promiseTimeout(1);
} while (spy.callCount === calls) } while (spy.callCount === calls)
} }

3
lib/utils.ts Normal file
View File

@@ -0,0 +1,3 @@
export function promiseTimeout(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}