diff --git a/lib/client.spec.ts b/lib/client.spec.ts index cb17adf75c..42ea57d2f8 100644 --- a/lib/client.spec.ts +++ b/lib/client.spec.ts @@ -371,6 +371,9 @@ describe('Client', () => { (await client.clientInfo()).db, 1 ); + }, { + // because of CLIENT INFO + minimumRedisVersion: [6, 2] }); itWithClient(TestRedisServers.OPEN, 'scanIterator', async client => { diff --git a/lib/commands/SMISMEMBER.spec.ts b/lib/commands/SMISMEMBER.spec.ts index f6130fb53c..320f60d4ba 100644 --- a/lib/commands/SMISMEMBER.spec.ts +++ b/lib/commands/SMISMEMBER.spec.ts @@ -1,8 +1,10 @@ import { strict as assert } from 'assert'; -import { TestRedisServers, itWithClient } from '../test-utils'; +import { TestRedisServers, itWithClient, describeHandleMinimumRedisVersion } from '../test-utils'; import { transformArguments } from './SMISMEMBER'; describe('SMISMEMBER', () => { + describeHandleMinimumRedisVersion([6, 2]); + it('transformArguments', () => { assert.deepEqual( transformArguments('key', ['1', '2']), diff --git a/lib/commands/XCLAIM.spec.ts b/lib/commands/XCLAIM.spec.ts index 434a4c5c79..ff4b445dcf 100644 --- a/lib/commands/XCLAIM.spec.ts +++ b/lib/commands/XCLAIM.spec.ts @@ -78,12 +78,9 @@ describe('XCLAIM', () => { }); itWithClient(TestRedisServers.OPEN, 'client.xClaim', async client => { - await Promise.all([ - client.xGroupCreate('key', 'group', '$', { - MKSTREAM: true - }), - client.xGroupCreateConsumer('key', 'group', 'consumer'), - ]); + await client.xGroupCreate('key', 'group', '$', { + MKSTREAM: true + }); assert.deepEqual( await client.xClaim('key', 'group', 'consumer', 1, '0-0'), diff --git a/lib/commands/XCLAIM_JUSTID.spec.ts b/lib/commands/XCLAIM_JUSTID.spec.ts index 700a95192a..bb31f2c453 100644 --- a/lib/commands/XCLAIM_JUSTID.spec.ts +++ b/lib/commands/XCLAIM_JUSTID.spec.ts @@ -11,12 +11,9 @@ describe('XCLAIM JUSTID', () => { }); itWithClient(TestRedisServers.OPEN, 'client.xClaimJustId', async client => { - await Promise.all([ - client.xGroupCreate('key', 'group', '$', { - MKSTREAM: true - }), - client.xGroupCreateConsumer('key', 'group', 'consumer'), - ]); + await client.xGroupCreate('key', 'group', '$', { + MKSTREAM: true + }); assert.deepEqual( await client.xClaimJustId('key', 'group', 'consumer', 1, '0-0'), diff --git a/lib/socket.ts b/lib/socket.ts index 699841034d..804bc766d6 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -1,8 +1,8 @@ import EventEmitter from 'events'; import net from 'net'; import tls from 'tls'; -import { setTimeout } from 'timers/promises'; import { URL } from 'url'; +import { promiseTimeout } from './utils'; interface RedisSocketCommonOptions { username?: string; @@ -147,7 +147,7 @@ export default class RedisSocket extends EventEmitter { throw retryIn; } - await setTimeout(retryIn); + await promiseTimeout(retryIn); return this.#retryConnection(retries + 1); } } diff --git a/lib/test-utils.ts b/lib/test-utils.ts index 1f775edb96..93ab7ce49f 100644 --- a/lib/test-utils.ts +++ b/lib/test-utils.ts @@ -7,10 +7,10 @@ import { once } from 'events'; import { RedisSocketOptions } from './socket'; import which from 'which'; import { SinonSpy } from 'sinon'; -import { setTimeout } from 'timers/promises'; import RedisCluster, { RedisClusterType } from './cluster'; import { unlink } from 'fs/promises'; import { Context as MochaContext } from 'mocha'; +import { promiseTimeout } from './utils'; type RedisVersion = [major: number, minor: number, patch: number]; @@ -41,6 +41,8 @@ export function isRedisVersionGreaterThan(minimumVersion: PartialRedisVersion | for (let i = 0; i < lastIndex; i++) { if (REDIS_VERSION[i] > minimumVersion[i]) { 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') { - await setTimeout(CLUSTER_NODE_TIMEOUT); + await promiseTimeout(CLUSTER_NODE_TIMEOUT); } const disconnectPromises = []; @@ -360,6 +362,6 @@ export async function waitTillBeenCalled(spy: SinonSpy): Promise { throw new Error('Waiting for more than 1 second'); } - await setTimeout(1); + await promiseTimeout(1); } while (spy.callCount === calls) } \ No newline at end of file diff --git a/lib/utils.ts b/lib/utils.ts new file mode 100644 index 0000000000..55bed41981 --- /dev/null +++ b/lib/utils.ts @@ -0,0 +1,3 @@ +export function promiseTimeout(ms: number): Promise { + return new Promise(resolve => setTimeout(resolve, ms)); +}