1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-10 11:43:01 +03:00

run some tests only on supported redis versions, use coveralls parallel mode

This commit is contained in:
leibale
2021-07-12 18:08:54 -04:00
parent b855150009
commit 31aa61bdda
43 changed files with 383 additions and 199 deletions

View File

@@ -7,13 +7,12 @@ on:
jobs: jobs:
tests: tests:
name: Tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node-version: [12.x, 14.x, 16.x] node-version: [12.x, 14.x, 16.x]
redis-version: [6.x, 5.x] redis-version: [5.x, 6.x]
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4
@@ -44,3 +43,15 @@ jobs:
uses: coverallsapp/github-action@v1.1.2 uses: coverallsapp/github-action@v1.1.2
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: Node ${{ matrix.node-version }} Redis ${{ matrix.redis-version }}
parallel: true
finish:
needs: tests
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true

View File

@@ -1,6 +1,6 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { once } from 'events'; import { once } from 'events';
import { itWithClient, TEST_REDIS_SERVERS, TestRedisServers, waitTillBeenCalled } from './test-utils'; import { itWithClient, TEST_REDIS_SERVERS, TestRedisServers, waitTillBeenCalled, isRedisVersionGreaterThan } from './test-utils';
import RedisClient from './client'; import RedisClient from './client';
import { AbortError } from './errors'; import { AbortError } from './errors';
import { defineScript } from './lua-script'; import { defineScript } from './lua-script';
@@ -26,7 +26,10 @@ describe('Client', () => {
await assert.rejects( await assert.rejects(
client.connect(), client.connect(),
{ {
message: 'WRONGPASS invalid username-password pair or user is disabled.'
message: isRedisVersionGreaterThan([6]) ?
'WRONGPASS invalid username-password pair or user is disabled.' :
'ERR invalid password'
} }
); );
@@ -114,7 +117,7 @@ describe('Client', () => {
}); });
it('client.{command} should accept mix of strings and array of strings', done => { it('client.{command} should accept mix of strings and array of strings', done => {
(client as any).set(['a'], 'b', ['GET'], (err?: Error, reply?: string) => { (client as any).set(['a'], 'b', ['XX'], (err?: Error, reply?: string) => {
if (err) { if (err) {
return done(err); return done(err);
} }

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_CAT'; import { transformArguments } from './ACL_CAT';
describe('ACL CAT', () => { describe('ACL CAT', () => {
describeHandleMinimumRedisVersion([6]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

View File

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

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_GENPASS'; import { transformArguments } from './ACL_GENPASS';
describe('ACL GENPASS', () => { describe('ACL GENPASS', () => {
describeHandleMinimumRedisVersion([6]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

View File

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

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_LIST'; import { transformArguments } from './ACL_LIST';
describe('ACL LIST', () => { describe('ACL LIST', () => {
describeHandleMinimumRedisVersion([6]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), transformArguments(),

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_SAVE'; import { transformArguments } from './ACL_SAVE';
describe('ACL SAVE', () => { describe('ACL SAVE', () => {
describeHandleMinimumRedisVersion([6]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), transformArguments(),

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_LOG'; import { transformArguments } from './ACL_LOG';
describe('ACL LOG', () => { describe('ACL LOG', () => {
describeHandleMinimumRedisVersion([6]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_LOG_RESET'; import { transformArguments } from './ACL_LOG_RESET';
describe('ACL LOG RESET', () => { describe('ACL LOG RESET', () => {
describeHandleMinimumRedisVersion([6]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), transformArguments(),

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_LOAD'; import { transformArguments } from './ACL_LOAD';
describe('ACL LOAD', () => { describe('ACL LOAD', () => {
describeHandleMinimumRedisVersion([6]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), transformArguments(),

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_SETUSER'; import { transformArguments } from './ACL_SETUSER';
describe('ACL SETUSER', () => { describe('ACL SETUSER', () => {
describeHandleMinimumRedisVersion([6]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_USERS'; import { transformArguments } from './ACL_USERS';
describe('ACL USERS', () => { describe('ACL USERS', () => {
describeHandleMinimumRedisVersion([6]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), transformArguments(),

View File

@@ -1,7 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './ACL_WHOAMI'; import { transformArguments } from './ACL_WHOAMI';
describe('ACL WHOAMI', () => { describe('ACL WHOAMI', () => {
describeHandleMinimumRedisVersion([6]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments(), transformArguments(),

View File

@@ -1,10 +1,12 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters } from '../test-utils'; import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters, describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './BLMOVE'; import { transformArguments } from './BLMOVE';
import RedisClient from '../client'; import RedisClient from '../client';
import RedisCluster from '../cluster'; import RedisCluster from '../cluster';
describe('BLMOVE', () => { describe('BLMOVE', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('source', 'destination', 'LEFT', 'RIGHT', 0), transformArguments('source', 'destination', 'LEFT', 'RIGHT', 0),

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, transformReply } from './COPY'; import { transformArguments, transformReply } from './COPY';
describe('COPY', () => { describe('COPY', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

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 './HRANDFIELD'; import { transformArguments } from './HRANDFIELD';
describe('HRANDFIELD', () => { describe('HRANDFIELD', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), transformArguments('key'),

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 './HRANDFIELD_COUNT'; import { transformArguments } from './HRANDFIELD_COUNT';
describe('HRANDFIELD COUNT', () => { describe('HRANDFIELD COUNT', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1), transformArguments('key', 1),

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 './HRANDFIELD_COUNT_WITHVALUES'; import { transformArguments } from './HRANDFIELD_COUNT_WITHVALUES';
describe('HRANDFIELD COUNT WITHVALUES', () => { describe('HRANDFIELD COUNT WITHVALUES', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1), transformArguments('key', 1),

View File

@@ -1,8 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters } from '../test-utils'; import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters, describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './LMOVE'; import { transformArguments } from './LMOVE';
describe('LMOVE', () => { describe('LMOVE', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('source', 'destination', 'LEFT', 'RIGHT'), transformArguments('source', 'destination', 'LEFT', 'RIGHT'),

View File

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

View File

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

View File

@@ -1,8 +1,10 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters } from '../test-utils'; import { TestRedisServers, itWithClient, itWithCluster, TestRedisClusters, describeHandleMinimumRedisVersion } from '../test-utils';
import { transformArguments } from './LPOS_COUNT'; import { transformArguments } from './LPOS_COUNT';
describe('LPOS COUNT', () => { describe('LPOS COUNT', () => {
describeHandleMinimumRedisVersion([6, 0, 6]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

View File

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

View File

@@ -114,6 +114,8 @@ describe('SET', () => {
}), }),
null null
); );
}, {
minimumRedisVersion: [6, 2]
}); });
}); });
}); });

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 './SISMEMBER'; import { transformArguments } from './SISMEMBER';
describe('SISMEMBER', () => { describe('SISMEMBER', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'member'), transformArguments('key', 'member'),

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 './XAUTOCLAIM'; import { transformArguments } from './XAUTOCLAIM';
describe('XAUTOCLAIM', () => { describe('XAUTOCLAIM', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

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 './XAUTOCLAIM_JUSTID'; import { transformArguments } from './XAUTOCLAIM_JUSTID';
describe('XAUTOCLAIM JUSTID', () => { describe('XAUTOCLAIM JUSTID', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'group', 'consumer', 1, '0-0'), transformArguments('key', 'group', 'consumer', 1, '0-0'),

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 './XGROUP_CREATECONSUMER'; import { transformArguments } from './XGROUP_CREATECONSUMER';
describe('XGROUP CREATECONSUMER', () => { describe('XGROUP CREATECONSUMER', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 'group', 'consumer'), transformArguments('key', 'group', 'consumer'),

View File

@@ -18,20 +18,46 @@ interface XInfoStreamReply {
lastEntry: StreamMessageReply | null; lastEntry: StreamMessageReply | null;
}; };
export function transformReply(reply: Array<any>): XInfoStreamReply { export function transformReply(rawReply: Array<any>): XInfoStreamReply {
return { const parsedReply: Partial<XInfoStreamReply> = {};
length: reply[1],
radixTreeKeys: reply[3], for (let i = 0; i < rawReply.length; i+= 2) {
radixTreeNodes: reply[5], switch (rawReply[i]) {
lastGeneratedId: reply[7], case 'length':
groups: reply[9], parsedReply.length = rawReply[i + 1];
firstEntry: reply[11] ? { break;
id: reply[11][0] ?? null,
message: transformReplyTuples(reply[11][1]) case 'radix-tree-keys':
} : null, parsedReply.radixTreeKeys = rawReply[i + 1];
lastEntry: reply[13] ? { break;
id: reply[13][0],
message: transformReplyTuples(reply[13][1]) case 'radix-tree-nodes':
} : null parsedReply.radixTreeNodes = rawReply[i + 1];
}; break;
case 'groups':
parsedReply.groups = rawReply[i + 1];
break;
case 'last-generated-id':
parsedReply.lastGeneratedId = rawReply[i + 1];
break;
case 'first-entry':
parsedReply.firstEntry = {
id: rawReply[i + 1][0],
message: transformReplyTuples(rawReply[i + 1][1])
};
break;
case 'last-entry':
parsedReply.lastEntry = {
id: rawReply[i + 1][0],
message: transformReplyTuples(rawReply[i + 1][1])
};
break;
}
}
return parsedReply as XInfoStreamReply;
} }

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 './ZDIFF'; import { transformArguments } from './ZDIFF';
describe('ZDIFF', () => { describe('ZDIFF', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(

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 './ZDIFFSTORE'; import { transformArguments } from './ZDIFFSTORE';
describe('ZDIFFSTORE', () => { describe('ZDIFFSTORE', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(

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 './ZDIFF_WITHSCORES'; import { transformArguments } from './ZDIFF_WITHSCORES';
describe('ZDIFF WITHSCORES', () => { describe('ZDIFF WITHSCORES', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(

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 './ZINTER'; import { transformArguments } from './ZINTER';
describe('ZINTER', () => { describe('ZINTER', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(

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 './ZINTER_WITHSCORES'; import { transformArguments } from './ZINTER_WITHSCORES';
describe('ZINTER WITHSCORES', () => { describe('ZINTER WITHSCORES', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(

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 './ZMSCORE'; import { transformArguments } from './ZMSCORE';
describe('ZMSCORE', () => { describe('ZMSCORE', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('string', () => { it('string', () => {
assert.deepEqual( assert.deepEqual(

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 './ZRANDMEMBER'; import { transformArguments } from './ZRANDMEMBER';
describe('ZRANDMEMBER', () => { describe('ZRANDMEMBER', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key'), transformArguments('key'),

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 './ZRANDMEMBER_COUNT'; import { transformArguments } from './ZRANDMEMBER_COUNT';
describe('ZRANDMEMBER COUNT', () => { describe('ZRANDMEMBER COUNT', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1), transformArguments('key', 1),

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 './ZRANDMEMBER_COUNT_WITHSCORES'; import { transformArguments } from './ZRANDMEMBER_COUNT_WITHSCORES';
describe('ZRANDMEMBER COUNT WITHSCORES', () => { describe('ZRANDMEMBER COUNT WITHSCORES', () => {
describeHandleMinimumRedisVersion([6, 2]);
it('transformArguments', () => { it('transformArguments', () => {
assert.deepEqual( assert.deepEqual(
transformArguments('key', 1), transformArguments('key', 1),

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 './ZRANGESTORE'; import { transformArguments } from './ZRANGESTORE';
describe('ZRANGESTORE', () => { describe('ZRANGESTORE', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('simple', () => { it('simple', () => {
assert.deepEqual( assert.deepEqual(

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 './ZUNION'; import { transformArguments } from './ZUNION';
describe('ZUNION', () => { describe('ZUNION', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(

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 './ZUNION_WITHSCORES'; import { transformArguments } from './ZUNION_WITHSCORES';
describe('ZUNION WITHSCORES', () => { describe('ZUNION WITHSCORES', () => {
describeHandleMinimumRedisVersion([6, 2]);
describe('transformArguments', () => { describe('transformArguments', () => {
it('key (string)', () => { it('key (string)', () => {
assert.deepEqual( assert.deepEqual(

View File

@@ -1,8 +1,8 @@
import assert from 'assert/strict'; import { strict as assert } from 'assert';
import RedisClient, { RedisClientType } from './client'; import RedisClient, { RedisClientType } from './client';
import { RedisModules } from './commands'; import { RedisModules } from './commands';
import { RedisLuaScripts } from './lua-script'; import { RedisLuaScripts } from './lua-script';
import { spawn } from 'child_process'; import { execSync, spawn } from 'child_process';
import { once } from 'events'; import { once } from 'events';
import { RedisSocketOptions } from './socket'; import { RedisSocketOptions } from './socket';
import which from 'which'; import which from 'which';
@@ -10,6 +10,29 @@ import { SinonSpy } from 'sinon';
import { setTimeout } from 'timers/promises'; 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';
type RedisVersion = [major: number, minor: number, patch: number];
type PartialRedisVersion = RedisVersion | [major: number, minor: number] | [major: number] | undefined;
const REDIS_VERSION = execSync('redis-server -v')
.toString()
.split('.', 3)
.map(Number) as RedisVersion;
export function isRedisVersionGreaterThan(minimumVersion: PartialRedisVersion): boolean {
if (minimumVersion === undefined) return true;
const lastIndex = minimumVersion.length - 1;
for (let i = 0; i < lastIndex; i++) {
if (minimumVersion[i] > REDIS_VERSION[i]) {
return true;
}
}
return minimumVersion[lastIndex] >= REDIS_VERSION[lastIndex];
}
export enum TestRedisServers { export enum TestRedisServers {
OPEN, OPEN,
@@ -24,102 +47,6 @@ export enum TestRedisClusters {
export const TEST_REDIS_CLUSTERES: Record<TestRedisClusters, Array<RedisSocketOptions>> = <any>{}; export const TEST_REDIS_CLUSTERES: Record<TestRedisClusters, Array<RedisSocketOptions>> = <any>{};
before(function () {
this.timeout(10000);
return Promise.all([
spawnOpenServer(),
spawnPasswordServer(),
spawnOpenCluster()
]);
});
async function spawnOpenServer(): Promise<void> {
TEST_REDIS_SERVERS[TestRedisServers.OPEN] = {
port: await spawnGlobalRedisServer()
};
}
async function spawnPasswordServer(): Promise<void> {
TEST_REDIS_SERVERS[TestRedisServers.PASSWORD] = {
port: await spawnGlobalRedisServer(['--requirepass', 'password']),
username: 'default',
password: 'password'
};
}
async function spawnOpenCluster(): Promise<void> {
TEST_REDIS_CLUSTERES[TestRedisClusters.OPEN] = (await spawnGlobalRedisCluster(TestRedisClusters.OPEN, 3)).map(port => ({
port
}));
}
export function itWithClient(type: TestRedisServers, title: string, fn: (client: RedisClientType<RedisModules, RedisLuaScripts>) => Promise<void>): void {
it(title, async () => {
const client = RedisClient.create({
socket: TEST_REDIS_SERVERS[type]
});
await client.connect();
try {
await client.flushAll();
await fn(client);
} finally {
await client.flushAll();
await client.disconnect();
}
});
}
export function itWithCluster(type: TestRedisClusters, title: string, fn: (cluster: RedisClusterType<RedisModules, RedisLuaScripts>) => Promise<void>): void {
it(title, async () => {
const cluster = RedisCluster.create({
rootNodes: TEST_REDIS_CLUSTERES[type]
});
await cluster.connect();
try {
await clusterFlushAll(cluster);
await fn(cluster);
} finally {
await clusterFlushAll(cluster);
await cluster.disconnect();
}
});
}
export function itWithDedicatedCluster(title: string, fn: (cluster: RedisClusterType<RedisModules, RedisLuaScripts>) => Promise<void>): void {
it(title, async function () {
this.timeout(10000);
const spawnResults = await spawnRedisCluster(null, 3),
cluster = RedisCluster.create({
rootNodes: [{
port: spawnResults[0].port
}]
});
await cluster.connect();
try {
await fn(cluster);
} finally {
await cluster.disconnect();
for (const { cleanup } of spawnResults) {
await cleanup();
}
}
});
}
async function clusterFlushAll(cluster: RedisCluster): Promise<void> {
await Promise.all(
cluster.getMasters().map(({ client }) => client.flushAll())
);
}
const REDIS_PATH = which.sync('redis-server'); const REDIS_PATH = which.sync('redis-server');
@@ -173,57 +100,6 @@ async function spawnGlobalRedisServer(args?: Array<string>): Promise<number> {
const SLOTS = 16384, const SLOTS = 16384,
CLUSTER_NODE_TIMEOUT = 2000; CLUSTER_NODE_TIMEOUT = 2000;
export async function spawnRedisCluster(type: TestRedisClusters | null, numberOfNodes: number, args?: Array<string>): Promise<Array<SpawnRedisServerResult>> {
const spawnPromises = [],
slotsPerNode = Math.floor(SLOTS / numberOfNodes);
for (let i = 0; i < numberOfNodes; i++) {
const fromSlot = i * slotsPerNode;
spawnPromises.push(
spawnRedisClusterNode(
type,
i,
fromSlot,
i === numberOfNodes - 1 ? SLOTS : fromSlot + slotsPerNode,
args
)
);
}
const spawnResults = await Promise.all(spawnPromises),
meetPromises = [];
for (let i = 1; i < spawnResults.length; i++) {
meetPromises.push(
spawnResults[i].client.clusterMeet(
'127.0.0.1',
spawnResults[i - 1].port
)
);
}
while ((await spawnResults[0].client.clusterInfo()).state !== 'ok') {
await setTimeout(CLUSTER_NODE_TIMEOUT);
}
const disconnectPromises = [];
for (const result of spawnResults) {
disconnectPromises.push(result.client.disconnect());
}
await Promise.all(disconnectPromises);
return spawnResults;
}
export async function spawnGlobalRedisCluster(type: TestRedisClusters | null, numberOfNodes: number, args?: Array<string>): Promise<Array<number>> {
const results = await spawnRedisCluster(type, numberOfNodes, args);
after(() => Promise.all(
results.map(({ cleanup }) => cleanup())
));
return results.map(({ port }) => port);
}
interface SpawnRedisClusterNodeResult extends SpawnRedisServerResult { interface SpawnRedisClusterNodeResult extends SpawnRedisServerResult {
client: RedisClientType<RedisModules, RedisLuaScripts> client: RedisClientType<RedisModules, RedisLuaScripts>
} }
@@ -281,6 +157,186 @@ async function spawnRedisClusterNode(
}; };
} }
export async function spawnRedisCluster(type: TestRedisClusters | null, numberOfNodes: number, args?: Array<string>): Promise<Array<SpawnRedisServerResult>> {
const spawnPromises = [],
slotsPerNode = Math.floor(SLOTS / numberOfNodes);
for (let i = 0; i < numberOfNodes; i++) {
const fromSlot = i * slotsPerNode;
spawnPromises.push(
spawnRedisClusterNode(
type,
i,
fromSlot,
i === numberOfNodes - 1 ? SLOTS : fromSlot + slotsPerNode,
args
)
);
}
const spawnResults = await Promise.all(spawnPromises),
meetPromises = [];
for (let i = 1; i < spawnResults.length; i++) {
meetPromises.push(
spawnResults[i].client.clusterMeet(
'127.0.0.1',
spawnResults[i - 1].port
)
);
}
while ((await spawnResults[0].client.clusterInfo()).state !== 'ok') {
await setTimeout(CLUSTER_NODE_TIMEOUT);
}
const disconnectPromises = [];
for (const result of spawnResults) {
disconnectPromises.push(result.client.disconnect());
}
await Promise.all(disconnectPromises);
return spawnResults;
}
export async function spawnGlobalRedisCluster(type: TestRedisClusters | null, numberOfNodes: number, args?: Array<string>): Promise<Array<number>> {
const results = await spawnRedisCluster(type, numberOfNodes, args);
after(() => Promise.all(
results.map(({ cleanup }) => cleanup())
));
return results.map(({ port }) => port);
}
async function spawnOpenServer(): Promise<void> {
TEST_REDIS_SERVERS[TestRedisServers.OPEN] = {
port: await spawnGlobalRedisServer()
};
}
async function spawnPasswordServer(): Promise<void> {
TEST_REDIS_SERVERS[TestRedisServers.PASSWORD] = {
port: await spawnGlobalRedisServer(['--requirepass', 'password']),
password: 'password'
};
}
async function spawnOpenCluster(): Promise<void> {
TEST_REDIS_CLUSTERES[TestRedisClusters.OPEN] = (await spawnGlobalRedisCluster(TestRedisClusters.OPEN, 3)).map(port => ({
port
}));
}
before(function () {
this.timeout(10000);
return Promise.all([
spawnOpenServer(),
spawnPasswordServer(),
spawnOpenCluster()
]);
});
interface RedisTestOptions {
minimumRedisVersion?: PartialRedisVersion;
}
export function handleMinimumRedisVersion(mochaContext: MochaContext, minimumRedisVersion: PartialRedisVersion): boolean {
if (isRedisVersionGreaterThan(minimumRedisVersion)) {
mochaContext.skip();
return true;
}
return false;
}
export function describeHandleMinimumRedisVersion(minimumRedisVersion: PartialRedisVersion): void {
before(function () {
handleMinimumRedisVersion(this, minimumRedisVersion);
});
}
export function itWithClient(
type: TestRedisServers,
title: string,
fn: (client: RedisClientType<RedisModules, RedisLuaScripts>) => Promise<void>,
options?: RedisTestOptions
): void {
it(title, async function () {
handleMinimumRedisVersion(this, options?.minimumRedisVersion);
const client = RedisClient.create({
socket: TEST_REDIS_SERVERS[type]
});
await client.connect();
try {
await client.flushAll();
await fn(client);
} finally {
await client.flushAll();
await client.disconnect();
}
});
}
export function itWithCluster(
type: TestRedisClusters,
title: string,
fn: (cluster: RedisClusterType<RedisModules, RedisLuaScripts>) => Promise<void>,
options?: RedisTestOptions
): void {
it(title, async function () {
handleMinimumRedisVersion(this, options?.minimumRedisVersion);
const cluster = RedisCluster.create({
rootNodes: TEST_REDIS_CLUSTERES[type]
});
await cluster.connect();
try {
await clusterFlushAll(cluster);
await fn(cluster);
} finally {
await clusterFlushAll(cluster);
await cluster.disconnect();
}
});
}
export function itWithDedicatedCluster(title: string, fn: (cluster: RedisClusterType<RedisModules, RedisLuaScripts>) => Promise<void>): void {
it(title, async function () {
this.timeout(10000);
const spawnResults = await spawnRedisCluster(null, 3),
cluster = RedisCluster.create({
rootNodes: [{
port: spawnResults[0].port
}]
});
await cluster.connect();
try {
await fn(cluster);
} finally {
await cluster.disconnect();
for (const { cleanup } of spawnResults) {
await cleanup();
}
}
});
}
async function clusterFlushAll(cluster: RedisCluster): Promise<void> {
await Promise.all(
cluster.getMasters().map(({ client }) => client.flushAll())
);
}
export async function waitTillBeenCalled(spy: SinonSpy): Promise<void> { export async function waitTillBeenCalled(spy: SinonSpy): Promise<void> {
const start = process.hrtime.bigint(), const start = process.hrtime.bigint(),
calls = spy.callCount; calls = spy.callCount;