From fbca5cda0a477c2c2bce2c85dcabfa1da9325ab4 Mon Sep 17 00:00:00 2001 From: Leibale Eidelman Date: Mon, 8 Mar 2021 14:12:26 -0500 Subject: [PATCH] Upgrade node and dependencies (#1578) * 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 f5528504a0b69ff7ca836868ead4590e491b8ef4 - 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) --- .github/workflows/benchmark.yml | 4 ++-- .github/workflows/tests.yml | 4 ++-- .github/workflows/tests_windows.yml | 2 +- lib/individualCommands.js | 2 +- package.json | 22 +++++++++---------- test/auth.spec.js | 34 +++++++++++++++++++---------- test/commands/client.spec.js | 6 ++--- test/commands/hgetall.spec.js | 7 +++--- test/commands/hlen.spec.js | 8 +++---- test/commands/hset.spec.js | 16 +++++++------- test/commands/monitor.spec.js | 4 ++-- test/conf/password.conf | 1 + test/conf/redis.conf | 1 + test/conf/rename.conf | 1 + test/conf/slave.conf | 1 + test/connection.spec.js | 13 +++++++---- test/detect_buffers.spec.js | 24 ++++++++++---------- test/errors.js | 6 +++++ test/multi.spec.js | 2 +- test/node_redis.spec.js | 14 +++++++----- test/pubsub.spec.js | 29 ++++++++++++------------ test/return_buffers.spec.js | 26 ++++++++++++---------- 22 files changed, 129 insertions(+), 98 deletions(-) create mode 100644 test/errors.js diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index c3db31f3bb1..3ec398bb627 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b3a608ac77f..06b0e57ec3e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.github/workflows/tests_windows.yml b/.github/workflows/tests_windows.yml index 2f5e7e441ab..7a2e00a9c93 100644 --- a/.github/workflows/tests_windows.yml +++ b/.github/workflows/tests_windows.yml @@ -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: diff --git a/lib/individualCommands.js b/lib/individualCommands.js index d366b642502..44973324993 100644 --- a/lib/individualCommands.js +++ b/lib/individualCommands.js @@ -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; diff --git a/package.json b/package.json index 75489c3ec44..a8ae6da26ea 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/auth.spec.js b/test/auth.spec.js index d88ac6304e3..995d98136b3 100644 --- a/test/auth.spec.js +++ b/test/auth.spec.js @@ -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') { @@ -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(); }); @@ -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(); }); }); @@ -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; @@ -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(); }); @@ -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(); @@ -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(); }); @@ -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(); }); }); @@ -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(); }); }); diff --git a/test/commands/client.spec.js b/test/commands/client.spec.js index 51a55e3f16b..3214243107c 100644 --- a/test/commands/client.spec.js +++ b/test/commands/client.spec.js @@ -57,7 +57,7 @@ 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)); }); @@ -65,7 +65,7 @@ describe("The 'client' method", function () { 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)); @@ -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'); diff --git a/test/commands/hgetall.spec.js b/test/commands/hgetall.spec.js index b74995427a1..5bfa609d0bc 100644 --- a/test/commands/hgetall.spec.js +++ b/test/commands/hgetall.spec.js @@ -50,7 +50,6 @@ describe("The 'hgetall' method", function () { }); describe('binary client', function () { - var client; var args = config.configureClient(ip, { return_buffers: true }); @@ -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); }); }); diff --git a/test/commands/hlen.spec.js b/test/commands/hlen.spec.js index f1f94fec025..874cb2970a1 100644 --- a/test/commands/hlen.spec.js +++ b/test/commands/hlen.spec.js @@ -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)); diff --git a/test/commands/hset.spec.js b/test/commands/hset.spec.js index d94a7aa0f2b..746176f3d8c 100644 --- a/test/commands/hset.spec.js +++ b/test/commands/hset.spec.js @@ -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)); @@ -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(); @@ -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(); diff --git a/test/commands/monitor.spec.js b/test/commands/monitor.spec.js index 7465ac4eb84..679277ffcac 100644 --- a/test/commands/monitor.spec.js +++ b/test/commands/monitor.spec.js @@ -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) { diff --git a/test/conf/password.conf b/test/conf/password.conf index c2b8feb4478..3b3c02f346e 100644 --- a/test/conf/password.conf +++ b/test/conf/password.conf @@ -3,3 +3,4 @@ port 6379 bind ::1 127.0.0.1 unixsocket /tmp/redis.sock unixsocketperm 700 +save "" diff --git a/test/conf/redis.conf b/test/conf/redis.conf index fad47a5fc63..9bf706c6543 100644 --- a/test/conf/redis.conf +++ b/test/conf/redis.conf @@ -2,3 +2,4 @@ port 6379 bind ::1 127.0.0.1 unixsocket /tmp/redis.sock unixsocketperm 700 +save "" \ No newline at end of file diff --git a/test/conf/rename.conf b/test/conf/rename.conf index ef839236558..207fe156221 100644 --- a/test/conf/rename.conf +++ b/test/conf/rename.conf @@ -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 diff --git a/test/conf/slave.conf b/test/conf/slave.conf index 31cd801c269..f5632bbffcb 100644 --- a/test/conf/slave.conf +++ b/test/conf/slave.conf @@ -4,3 +4,4 @@ unixsocket /tmp/redis6381.sock unixsocketperm 700 slaveof localhost 6379 masterauth porkchopsandwiches +save "" diff --git a/test/connection.spec.js b/test/connection.spec.js index 7c153b3926e..26a982a92cc 100644 --- a/test/connection.spec.js +++ b/test/connection.spec.js @@ -14,6 +14,8 @@ describe('connection tests', function () { client = null; }); afterEach(function () { + if (!client) return; + client.end(true); }); @@ -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(); @@ -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'); @@ -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); diff --git a/test/detect_buffers.spec.js b/test/detect_buffers.spec.js index a656c549435..faa63efb1f1 100644 --- a/test/detect_buffers.spec.js +++ b/test/detect_buffers.spec.js @@ -43,7 +43,7 @@ describe('detect_buffers', function () { describe('first argument is a buffer', function () { it('returns a buffer', function (done) { - client.get(new Buffer('string key 1'), function (err, reply) { + client.get(Buffer.from('string key 1'), function (err, reply) { assert.strictEqual(true, Buffer.isBuffer(reply)); assert.strictEqual('', reply.inspect()); return done(err); @@ -51,7 +51,7 @@ describe('detect_buffers', function () { }); it('returns a bufffer when executed as part of transaction', function (done) { - client.multi().get(new Buffer('string key 1')).exec(function (err, reply) { + client.multi().get(Buffer.from('string key 1')).exec(function (err, reply) { assert.strictEqual(1, reply.length); assert.strictEqual(true, Buffer.isBuffer(reply[0])); assert.strictEqual('', reply[0].inspect()); @@ -65,8 +65,8 @@ describe('detect_buffers', function () { it('can interleave string and buffer results', function (done) { client.multi() .hget('hash key 2', 'key 1') - .hget(new Buffer('hash key 2'), 'key 1') - .hget('hash key 2', new Buffer('key 2')) + .hget(Buffer.from('hash key 2'), 'key 1') + .hget('hash key 2', Buffer.from('key 2')) .hget('hash key 2', 'key 2') .exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); @@ -86,8 +86,8 @@ describe('detect_buffers', function () { it('can interleave string and buffer results', function (done) { client.batch() .hget('hash key 2', 'key 1') - .hget(new Buffer('hash key 2'), 'key 1') - .hget('hash key 2', new Buffer('key 2')) + .hget(Buffer.from('hash key 2'), 'key 1') + .hget('hash key 2', Buffer.from('key 2')) .hget('hash key 2', 'key 2') .exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); @@ -150,7 +150,7 @@ describe('detect_buffers', function () { describe('first argument is a buffer', function () { it('returns buffers for keys requested', function (done) { - client.hmget(new Buffer('hash key 2'), 'key 1', 'key 2', function (err, reply) { + client.hmget(Buffer.from('hash key 2'), 'key 1', 'key 2', function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(2, reply.length); assert.strictEqual(true, Buffer.isBuffer(reply[0])); @@ -162,7 +162,7 @@ describe('detect_buffers', function () { }); it('returns buffers for keys requested in transaction', function (done) { - client.multi().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { + client.multi().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(1, reply.length); assert.strictEqual(2, reply[0].length); @@ -175,7 +175,7 @@ describe('detect_buffers', function () { }); it('returns buffers for keys requested in .batch', function (done) { - client.batch().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { + client.batch().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(1, reply.length); assert.strictEqual(2, reply[0].length); @@ -226,7 +226,7 @@ describe('detect_buffers', function () { describe('first argument is a buffer', function () { it('returns buffer values', function (done) { - client.hgetall(new Buffer('hash key 2'), function (err, reply) { + client.hgetall(Buffer.from('hash key 2'), function (err, reply) { assert.strictEqual(null, err); assert.strictEqual('object', typeof reply); assert.strictEqual(2, Object.keys(reply).length); @@ -239,7 +239,7 @@ describe('detect_buffers', function () { }); it('returns buffer values when executed in transaction', function (done) { - client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { + client.multi().hgetall(Buffer.from('hash key 2')).exec(function (err, reply) { assert.strictEqual(1, reply.length); assert.strictEqual('object', typeof reply[0]); assert.strictEqual(2, Object.keys(reply[0]).length); @@ -252,7 +252,7 @@ describe('detect_buffers', function () { }); it('returns buffer values when executed in .batch', function (done) { - client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { + client.batch().hgetall(Buffer.from('hash key 2')).exec(function (err, reply) { assert.strictEqual(1, reply.length); assert.strictEqual('object', typeof reply[0]); assert.strictEqual(2, Object.keys(reply[0]).length); diff --git a/test/errors.js b/test/errors.js new file mode 100644 index 00000000000..060afab585a --- /dev/null +++ b/test/errors.js @@ -0,0 +1,6 @@ +'use strict'; + +module.exports = { + invalidPassword: /^(ERR invalid password|WRONGPASS invalid username-password pair)/, + subscribeUnsubscribeOnly: /^ERR( Can't execute 'get':)? only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/ +}; diff --git a/test/multi.spec.js b/test/multi.spec.js index 2465dfc2d0b..5b0e801c875 100644 --- a/test/multi.spec.js +++ b/test/multi.spec.js @@ -46,7 +46,7 @@ describe("The 'multi' method", function () { } var json = JSON.stringify(test_arr); - zlib.deflate(new Buffer(json), function (err, buffer) { + zlib.deflate(Buffer.from(json), function (err, buffer) { if (err) { done(err); return; diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index a2c7fac69e0..12ad70d5ef6 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -83,10 +83,11 @@ describe('The node_redis client', function () { client.once('reconnecting', function () { process.nextTick(function () { assert.strictEqual(client.reply_parser.buffer, null); + client.end(true); done(); }); }); - var partialInput = new Buffer('$100\r\nabcdef'); + var partialInput = Buffer.from('$100\r\nabcdef'); client.reply_parser.execute(partialInput); assert.strictEqual(client.reply_parser.buffer.inspect(), partialInput.inspect()); client.stream.destroy(); @@ -531,11 +532,11 @@ describe('The node_redis client', function () { // TODO: Investigate why this test is failing hard and killing mocha if using '/tmp/redis.sock'. // Seems like something is wrong with nyc while passing a socket connection to create client! - client = redis.createClient(); - client.quit(function () { - client.get('foo', function (err, res) { + var client2 = redis.createClient(); + client2.quit(function () { + client2.get('foo', function (err, res) { assert.strictEqual(err.message, 'Stream connection ended and command aborted. It might have been processed.'); - assert.strictEqual(client.offline_queue.length, 0); + assert.strictEqual(client2.offline_queue.length, 0); done(); }); }); @@ -702,6 +703,7 @@ describe('The node_redis client', function () { // Recreate client in domain so error handlers run this domain // Changed in: "error handler runs outside of its domain" // https://github.com/nodejs/node/pull/26211 + client.end(true); // make sure to close current client client = redis.createClient(); } client.end(true); @@ -811,7 +813,7 @@ describe('The node_redis client', function () { // ready is called in a reply process.nextTick(function () { // Fail the set answer. Has no corresponding command obj and will therefore land in the error handler and set - client.reply_parser.execute(new Buffer('a*1\r*1\r$1`zasd\r\na')); + client.reply_parser.execute(Buffer.from('a*1\r*1\r$1`zasd\r\na')); }); }); }); diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index e0c71adf91d..34e93f37f2c 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -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; describe('publish/subscribe', function () { @@ -124,7 +125,7 @@ describe('publish/subscribe', function () { detect_buffers: true }); sub.on('subscribe', function (chnl, count) { - if (chnl.inspect() === new Buffer([0xAA, 0xBB, 0x00, 0xF0]).inspect()) { + if (chnl.inspect() === Buffer.from([0xAA, 0xBB, 0x00, 0xF0]).inspect()) { assert.equal(1, count); if (a) { return done(); @@ -137,7 +138,7 @@ describe('publish/subscribe', function () { a = true; }); - sub.subscribe(new Buffer([0xAA, 0xBB, 0x00, 0xF0]), channel2); + sub.subscribe(Buffer.from([0xAA, 0xBB, 0x00, 0xF0]), channel2); }); it('receives messages on subscribed channel', function (done) { @@ -262,13 +263,13 @@ describe('publish/subscribe', function () { }); it('handles multiple channels with the same channel name properly, even with buffers', function (done) { - var channels = ['a', 'b', 'a', new Buffer('a'), 'c', 'b']; + var channels = ['a', 'b', 'a', Buffer.from('a'), 'c', 'b']; var subscribed_channels = [1, 2, 2, 2, 3, 3]; var i = 0; sub.subscribe(channels); sub.on('subscribe', function (channel, count) { if (Buffer.isBuffer(channel)) { - assert.strictEqual(channel.inspect(), new Buffer(channels[i]).inspect()); + assert.strictEqual(channel.inspect(), Buffer.from(channels[i]).inspect()); } else { assert.strictEqual(channel, channels[i].toString()); } @@ -420,7 +421,7 @@ describe('publish/subscribe', function () { }); subscribe(['prefix:*', 'prefix:3'], function () { - pub.publish('prefix:1', new Buffer('test'), function () { + pub.publish('prefix:1', Buffer.from('test'), function () { subscribe(['prefix:2']); subscribe(['5', 'test:a', 'bla'], function () { assert(all); @@ -494,9 +495,9 @@ describe('publish/subscribe', function () { sub2.batch().psubscribe('*', helper.isString('*')).exec(); sub2.subscribe('/foo'); sub2.on('pmessage', function (pattern, channel, message) { - assert.strictEqual(pattern.inspect(), new Buffer('*').inspect()); - assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); - assert.strictEqual(message.inspect(), new Buffer('hello world').inspect()); + assert.strictEqual(pattern.inspect(), Buffer.from('*').inspect()); + assert.strictEqual(channel.inspect(), Buffer.from('/foo').inspect()); + assert.strictEqual(message.inspect(), Buffer.from('hello world').inspect()); sub2.quit(done); }); pub.pubsub('numsub', '/foo', function (err, res) { @@ -517,11 +518,11 @@ describe('publish/subscribe', function () { assert.strictEqual(sub.shouldBuffer, false); sub.on('pmessageBuffer', function (pattern, channel) { if (typeof pattern === 'string') { - pattern = new Buffer(pattern); - channel = new Buffer(channel); + pattern = Buffer.from(pattern); + channel = Buffer.from(channel); } - assert.strictEqual(pattern.inspect(), new Buffer('*').inspect()); - assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); + assert.strictEqual(pattern.inspect(), Buffer.from('*').inspect()); + assert.strictEqual(channel.inspect(), Buffer.from('/foo').inspect()); sub.quit(end); }); // Either message_buffers or buffers has to be true, but not both at the same time @@ -587,7 +588,7 @@ describe('publish/subscribe', function () { }); // Get is forbidden sub.get('foo', function (err, res) { - assert(/^ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message)); + assert.ok(errors.subscribeUnsubscribeOnly.test(err.message)); assert.strictEqual(err.command, 'GET'); }); // Quit is allowed @@ -597,7 +598,7 @@ describe('publish/subscribe', function () { it('emit error if only pub sub commands are allowed without callback', function (done) { sub.subscribe('channel'); sub.on('error', function (err) { - assert(/^ERR only \(P\)SUBSCRIBE \/ \(P\)UNSUBSCRIBE/.test(err.message)); + assert.ok(errors.subscribeUnsubscribeOnly.test(err.message)); assert.strictEqual(err.command, 'GET'); done(); }); diff --git a/test/return_buffers.spec.js b/test/return_buffers.spec.js index ba40c26c373..22efb31a04f 100644 --- a/test/return_buffers.spec.js +++ b/test/return_buffers.spec.js @@ -40,6 +40,10 @@ describe('return_buffers', function () { }); }); + afterEach(function () { + client.end(true); + }); + describe('get', function () { describe('first argument is a string', function () { it('returns a buffer', function (done) { @@ -65,8 +69,8 @@ describe('return_buffers', function () { it('returns buffers', function (done) { client.multi() .hget('hash key 2', 'key 1') - .hget(new Buffer('hash key 2'), 'key 1') - .hget('hash key 2', new Buffer('key 2')) + .hget(Buffer.from('hash key 2'), 'key 1') + .hget('hash key 2', Buffer.from('key 2')) .hget('hash key 2', 'key 2') .exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); @@ -87,8 +91,8 @@ describe('return_buffers', function () { it('returns buffers', function (done) { client.batch() .hget('hash key 2', 'key 1') - .hget(new Buffer('hash key 2'), 'key 1') - .hget('hash key 2', new Buffer('key 2')) + .hget(Buffer.from('hash key 2'), 'key 1') + .hget('hash key 2', Buffer.from('key 2')) .hget('hash key 2', 'key 2') .exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); @@ -121,7 +125,7 @@ describe('return_buffers', function () { describe('first argument is a buffer', function () { it('returns buffers for keys requested', function (done) { - client.hmget(new Buffer('hash key 2'), 'key 1', 'key 2', function (err, reply) { + client.hmget(Buffer.from('hash key 2'), 'key 1', 'key 2', function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(2, reply.length); assert.strictEqual(true, Buffer.isBuffer(reply[0])); @@ -133,7 +137,7 @@ describe('return_buffers', function () { }); it('returns buffers for keys requested in transaction', function (done) { - client.multi().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { + client.multi().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(1, reply.length); assert.strictEqual(2, reply[0].length); @@ -146,7 +150,7 @@ describe('return_buffers', function () { }); it('returns buffers for keys requested in .batch', function (done) { - client.batch().hmget(new Buffer('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { + client.batch().hmget(Buffer.from('hash key 2'), 'key 1', 'key 2').exec(function (err, reply) { assert.strictEqual(true, Array.isArray(reply)); assert.strictEqual(1, reply.length); assert.strictEqual(2, reply[0].length); @@ -197,7 +201,7 @@ describe('return_buffers', function () { describe('first argument is a buffer', function () { it('returns buffer values', function (done) { - client.hgetall(new Buffer('hash key 2'), function (err, reply) { + client.hgetall(Buffer.from('hash key 2'), function (err, reply) { assert.strictEqual(null, err); assert.strictEqual('object', typeof reply); assert.strictEqual(2, Object.keys(reply).length); @@ -210,7 +214,7 @@ describe('return_buffers', function () { }); it('returns buffer values when executed in transaction', function (done) { - client.multi().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { + client.multi().hgetall(Buffer.from('hash key 2')).exec(function (err, reply) { assert.strictEqual(1, reply.length); assert.strictEqual('object', typeof reply[0]); assert.strictEqual(2, Object.keys(reply[0]).length); @@ -223,7 +227,7 @@ describe('return_buffers', function () { }); it('returns buffer values when executed in .batch', function (done) { - client.batch().hgetall(new Buffer('hash key 2')).exec(function (err, reply) { + client.batch().hgetall(Buffer.from('hash key 2')).exec(function (err, reply) { assert.strictEqual(1, reply.length); assert.strictEqual('object', typeof reply[0]); assert.strictEqual(2, Object.keys(reply[0]).length); @@ -241,7 +245,7 @@ describe('return_buffers', function () { var pub; var sub; var channel = 'test channel'; - var message = new Buffer('test message'); + var message = Buffer.from('test message'); var args = config.configureClient(ip, { return_buffers: true