Skip to content

Commit

Permalink
Upgrade node and dependencies (#1578)
Browse files Browse the repository at this point in the history
* upgrade workflow actions

* fix setup-node version

* change redis-64 version to 3.0.503

* fix "no password is set" for redis6,
fix tests to work with redis6,
add redis6 to workflows

* do not use assert.match (was added only at v13.6.0 & v12.16.0)

* fix errors.subscribeUnsubscribeOnly regex

* fix invaliodPassword typo

* send --save "" to redis-server in tests

* upgrade dependencies, set node minimum version to 10, use current LTS versions in tests and benchmark workflows

* change windows tests too

* revert mocha back to ^4.1.0

* fix for f552850 - revert mocha back to ^4.1.0

* fix some tests and upgrade mocha

* fix two more tests

* try to fix tests in windows

* upgrade denque and redis-commands
ref #1575

* replace `new Buffer` (deprecated) with `Buffer.from`

* Buffer.from(0) should be Buffer.alloc(0)
  • Loading branch information
leibale committed Mar 8, 2021
1 parent 2188744 commit fbca5cd
Show file tree
Hide file tree
Showing 22 changed files with 129 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [8.x, 10.x, 12.x]
redis-version: [5]
node-version: [10.x, 12.x, 14.x, 15.x]
redis-version: [5.x, 6.x]

steps:
- uses: actions/checkout@v2.3.4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Expand Up @@ -9,8 +9,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [6.x, 8.x, 10.x, 12.x]
redis-version: [4.x, 5.x]
node-version: [10.x, 12.x, 14.x, 15.x]
redis-version: [4.x, 5.x, 6.x]

steps:
- uses: actions/checkout@v2.3.4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests_windows.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [6.x, 8.x, 10.x, 12.x]
node-version: [10.x, 12.x, 14.x, 15.x]
steps:
- uses: actions/checkout@v2.3.4
with:
Expand Down
2 changes: 1 addition & 1 deletion lib/individualCommands.js
Expand Up @@ -4,7 +4,7 @@ var utils = require('./utils');
var debug = require('./debug');
var Multi = require('./multi');
var Command = require('./command');
var no_password_is_set = /no password is set/;
var no_password_is_set = /no password is set|called without any password configured/;
var loading = /LOADING/;
var RedisClient = require('../').RedisClient;

Expand Down
22 changes: 11 additions & 11 deletions package.json
Expand Up @@ -30,33 +30,33 @@
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"coverage": "nyc report --reporter=html",
"benchmark": "node benchmarks/multi_bench.js",
"test": "nyc --cache mocha ./test/*.js ./test/commands/*.js --timeout=8000 && npm run coverage",
"test": "nyc --cache mocha ./test/*.spec.js ./test/commands/*.spec.js --timeout=8000 && npm run coverage",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:report": "eslint --output-file=eslint-report.json --format=json .",
"compare": "node benchmarks/diff_multi_bench_output.js beforeBench.txt afterBench.txt"
},
"dependencies": {
"denque": "^1.4.1",
"redis-commands": "^1.5.0",
"denque": "^1.5.0",
"redis-commands": "^1.7.0",
"redis-errors": "^1.2.0",
"redis-parser": "^3.0.0"
},
"engines": {
"node": ">=6"
"node": ">=10"
},
"devDependencies": {
"prettier": "^1.19.1",
"bluebird": "^3.7.2",
"coveralls": "^2.11.2",
"eslint": "^6.8.0",
"coveralls": "^3.1.0",
"cross-spawn": "^7.0.3",
"eslint": "^7.21.0",
"intercept-stdout": "~0.1.2",
"metrics": "^0.1.21",
"mocha": "^4.1.0",
"nyc": "^14.1.1",
"mocha": "^8.3.0",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"tcp-port-used": "^1.0.1",
"uuid": "^3.4.0",
"cross-spawn": "^6.0.5"
"uuid": "^8.3.2"
},
"repository": {
"type": "git",
Expand Down
34 changes: 22 additions & 12 deletions test/auth.spec.js
Expand Up @@ -3,6 +3,7 @@
var assert = require('assert');
var config = require('./lib/config');
var helper = require('./helper');
var errors = require('./errors');
var redis = config.redis;

if (process.platform === 'win32') {
Expand Down Expand Up @@ -70,11 +71,13 @@ describe('client authentication', function () {
it('emits error when auth is bad without callback', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();

client = redis.createClient.apply(null, args);
client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));

client.once('error', function (err) {
assert.strictEqual(err.command, 'AUTH');
assert.ok(/ERR invalid password/.test(err.message));
assert.ok(errors.invalidPassword.test(err.message));
return done();
});

Expand All @@ -84,11 +87,13 @@ describe('client authentication', function () {
it('returns an error when auth is bad (empty string) with a callback', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();

client = redis.createClient.apply(null, args);
client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));

client.auth('', function (err, res) {
assert.strictEqual(err.command, 'AUTH');
assert.ok(/ERR invalid password/.test(err.message));
assert.ok(errors.invalidPassword.test(err.message));
done();
});
});
Expand Down Expand Up @@ -190,10 +195,12 @@ describe('client authentication', function () {
it('should return an error if the password is not correct and a callback has been provided', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();

client = redis.createClient.apply(null, args);
client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));
var async = true;
client.auth('undefined', function (err, res) {
assert.strictEqual(err.message, 'ERR invalid password');
assert.ok(errors.invalidPassword.test(err.message));
assert.strictEqual(err.command, 'AUTH');
assert.strictEqual(res, undefined);
async = false;
Expand All @@ -205,9 +212,11 @@ describe('client authentication', function () {
it('should emit an error if the password is not correct and no callback has been provided', function (done) {
if (helper.redisProcess().spawnFailed()) this.skip();

client = redis.createClient.apply(null, args);
client = redis.createClient.apply(null, config.configureClient(ip, {
no_ready_check: true
}));
client.on('error', function (err) {
assert.strictEqual(err.message, 'ERR invalid password');
assert.ok(errors.invalidPassword.test(err.message));
assert.strictEqual(err.command, 'AUTH');
done();
});
Expand Down Expand Up @@ -235,7 +244,7 @@ describe('client authentication', function () {
client = redis.createClient.apply(null, args);
client.on('ready', function () {
client.set('foo', 'bar', function (err, res) {
assert.equal(err.message, 'NOAUTH Authentication required.');
assert.ok(/^NOAUTH Authentication required\.(\r\n)?$/.test(err.message));
assert.equal(err.code, 'NOAUTH');
assert.equal(err.command, 'SET');
done();
Expand All @@ -248,7 +257,7 @@ describe('client authentication', function () {
client = redis.createClient.apply(null, args);
client.on('error', function (err) {
assert.equal(err.code, 'NOAUTH');
assert.equal(err.message, 'Ready check failed: NOAUTH Authentication required.');
assert.ok(/^Ready check failed: NOAUTH Authentication required\.(\r\n)?$/.test(err.message));
assert.equal(err.command, 'INFO');
done();
});
Expand All @@ -258,9 +267,10 @@ describe('client authentication', function () {
if (helper.redisProcess().spawnFailed()) this.skip();
client = redis.createClient({
password: 'wrong_password',
no_ready_check: true
});
client.once('error', function (err) {
assert.strictEqual(err.message, 'ERR invalid password');
assert.ok(errors.invalidPassword.test(err.message));
done();
});
});
Expand All @@ -277,7 +287,7 @@ describe('client authentication', function () {
client.once('ready', function () {
assert.strictEqual(client.pub_sub_mode, 1);
client.get('foo', function (err, res) {
assert(/ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message));
assert.ok(errors.subscribeUnsubscribeOnly.test(err.message));
done();
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/commands/client.spec.js
Expand Up @@ -57,15 +57,15 @@ describe("The 'client' method", function () {
it('off', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON');
client.client(new Buffer('REPLY'), 'OFF', helper.isUndefined());
client.client(Buffer.from('REPLY'), 'OFF', helper.isUndefined());
assert.strictEqual(client.reply, 'OFF');
client.set('foo', 'bar', helper.isUndefined(done));
});

it('skip', function (done) {
helper.serverVersionAtLeast.call(this, client, [3, 2, 0]);
assert.strictEqual(client.reply, 'ON');
client.client('REPLY', new Buffer('SKIP'), helper.isUndefined());
client.client('REPLY', Buffer.from('SKIP'), helper.isUndefined());
assert.strictEqual(client.reply, 'SKIP_ONE_MORE');
client.set('foo', 'bar', helper.isUndefined());
client.get('foo', helper.isString('bar', done));
Expand All @@ -91,7 +91,7 @@ describe("The 'client' method", function () {
var batch = client.batch();
assert.strictEqual(client.reply, 'ON');
batch.set('hello', 'world');
batch.client(new Buffer('REPLY'), new Buffer('OFF'), helper.isUndefined());
batch.client(Buffer.from('REPLY'), Buffer.from('OFF'), helper.isUndefined());
batch.set('foo', 'bar', helper.isUndefined());
batch.exec(function (err, res) {
assert.strictEqual(client.reply, 'OFF');
Expand Down
7 changes: 3 additions & 4 deletions test/commands/hgetall.spec.js
Expand Up @@ -50,7 +50,6 @@ describe("The 'hgetall' method", function () {
});

describe('binary client', function () {
var client;
var args = config.configureClient(ip, {
return_buffers: true
});
Expand All @@ -63,14 +62,14 @@ describe("The 'hgetall' method", function () {
});

it('returns binary results', function (done) {
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'));
client.hmset(['bhosts', 'mjr', '1', 'another', '23', 'home', '1234', Buffer.from([0xAA, 0xBB, 0x00, 0xF0]), Buffer.from([0xCC, 0xDD, 0x00, 0xF0])], helper.isString('OK'));
client.HGETALL('bhosts', function (err, obj) {
assert.strictEqual(4, Object.keys(obj).length);
assert.strictEqual('1', obj.mjr.toString());
assert.strictEqual('23', obj.another.toString());
assert.strictEqual('1234', obj.home.toString());
assert.strictEqual((new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]);
assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
assert.strictEqual((Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3]);
assert.strictEqual((Buffer.from([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(Buffer.from([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'));
return done(err);
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/commands/hlen.spec.js
Expand Up @@ -20,10 +20,10 @@ describe("The 'hlen' method", function () {

it('reports the count of keys', function (done) {
var hash = 'test hash';
var field1 = new Buffer('0123456789');
var value1 = new Buffer('abcdefghij');
var field2 = new Buffer(0);
var value2 = new Buffer(0);
var field1 = Buffer.from('0123456789');
var value1 = Buffer.from('abcdefghij');
var field2 = Buffer.alloc(0);
var value2 = Buffer.alloc(0);

client.HSET(hash, field1, value1, helper.isNumber(1));
client.HSET(hash, field2, value2, helper.isNumber(1));
Expand Down
16 changes: 8 additions & 8 deletions test/commands/hset.spec.js
Expand Up @@ -21,24 +21,24 @@ describe("The 'hset' method", function () {
});

it('allows a value to be set in a hash', function (done) {
var field = new Buffer('0123456789');
var value = new Buffer('abcdefghij');
var field = Buffer.from('0123456789');
var value = Buffer.from('abcdefghij');

client.hset(hash, field, value, helper.isNumber(1));
client.HGET(hash, field, helper.isString(value.toString(), done));
});

it('handles an empty value', function (done) {
var field = new Buffer('0123456789');
var value = new Buffer(0);
var field = Buffer.from('0123456789');
var value = Buffer.alloc(0);

client.HSET(hash, field, value, helper.isNumber(1));
client.HGET([hash, field], helper.isString('', done));
});

it('handles empty key and value', function (done) {
var field = new Buffer(0);
var value = new Buffer(0);
var field = Buffer.alloc(0);
var value = Buffer.alloc(0);
client.HSET([hash, field, value], function (err, res) {
assert.strictEqual(res, 1);
client.HSET(hash, field, value, helper.isNumber(0, done));
Expand All @@ -60,7 +60,7 @@ describe("The 'hset' method", function () {
it('does not error when a buffer and date are set as values on the same hash', function (done) {
var hash = 'test hash';
var field1 = 'buffer';
var value1 = new Buffer('abcdefghij');
var value1 = Buffer.from('abcdefghij');
var field2 = 'date';
var value2 = new Date();

Expand All @@ -70,7 +70,7 @@ describe("The 'hset' method", function () {
it('does not error when a buffer and date are set as fields on the same hash', function (done) {
var hash = 'test hash';
var value1 = 'buffer';
var field1 = new Buffer('abcdefghij');
var field1 = Buffer.from('abcdefghij');
var value2 = 'date';
var field2 = new Date();

Expand Down
4 changes: 2 additions & 2 deletions test/commands/monitor.spec.js
Expand Up @@ -90,8 +90,8 @@ describe("The 'monitor' method", function () {

monitorClient.MONITOR(function (err, res) {
assert.strictEqual(monitorClient.monitoring, true);
assert.strictEqual(res.inspect(), new Buffer('OK').inspect());
monitorClient.mget('hello', new Buffer('world'));
assert.strictEqual(res.inspect(), Buffer.from('OK').inspect());
monitorClient.mget('hello', Buffer.from('world'));
});

monitorClient.on('monitor', function (time, args, rawOutput) {
Expand Down
1 change: 1 addition & 0 deletions test/conf/password.conf
Expand Up @@ -3,3 +3,4 @@ port 6379
bind ::1 127.0.0.1
unixsocket /tmp/redis.sock
unixsocketperm 700
save ""
1 change: 1 addition & 0 deletions test/conf/redis.conf
Expand Up @@ -2,3 +2,4 @@ port 6379
bind ::1 127.0.0.1
unixsocket /tmp/redis.sock
unixsocketperm 700
save ""
1 change: 1 addition & 0 deletions test/conf/rename.conf
Expand Up @@ -2,6 +2,7 @@ port 6379
bind ::1 127.0.0.1
unixsocket /tmp/redis.sock
unixsocketperm 700
save ""
rename-command SET 807081f5afa96845a02816a28b7258c3
rename-command GET f397808a43ceca3963e22b4e13deb672
rename-command GETRANGE 9e3102b15cf231c4e9e940f284744fe0
1 change: 1 addition & 0 deletions test/conf/slave.conf
Expand Up @@ -4,3 +4,4 @@ unixsocket /tmp/redis6381.sock
unixsocketperm 700
slaveof localhost 6379
masterauth porkchopsandwiches
save ""
13 changes: 9 additions & 4 deletions test/connection.spec.js
Expand Up @@ -14,6 +14,8 @@ describe('connection tests', function () {
client = null;
});
afterEach(function () {
if (!client) return;

client.end(true);
});

Expand Down Expand Up @@ -238,7 +240,8 @@ describe('connection tests', function () {
client = redis.createClient({
retryStrategy: function (options) {
if (options.totalRetryTime > 150) {
client.set('foo', 'bar', function (err, res) {
client.set('foo', 'bar');
client.once('error', function (err) {
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
assert.strictEqual(err.origin.message, 'Connection timeout');
done();
Expand All @@ -256,7 +259,8 @@ describe('connection tests', function () {
client = redis.createClient({
retry_strategy: function (options) {
if (options.total_retry_time > 150) {
client.set('foo', 'bar', function (err, res) {
client.set('foo', 'bar');
client.once('error', function (err) {
assert.strictEqual(err.message, 'Redis connection in broken state: retry aborted.');
assert.strictEqual(err.code, 'CONNECTION_BROKEN');
assert.strictEqual(err.origin.code, 'ECONNREFUSED');
Expand Down Expand Up @@ -334,9 +338,10 @@ describe('connection tests', function () {

it('use the system socket timeout if the connect_timeout has not been provided', function (done) {
client = redis.createClient({
host: '2001:db8::ff00:42:8329' // auto detect ip v6
host: '0:0:0:0:0:0:0:1', // auto detect ip v6
no_ready_check: true
});
assert.strictEqual(client.address, '2001:db8::ff00:42:8329:6379');
assert.strictEqual(client.address, '0:0:0:0:0:0:0:1:6379');
assert.strictEqual(client.connection_options.family, 6);
process.nextTick(function () {
assert.strictEqual(client.stream.listeners('timeout').length, 0);
Expand Down

0 comments on commit fbca5cd

Please sign in to comment.