1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

tests: fix CI failures

This commit is contained in:
Mike Diarmid
2020-02-07 01:56:03 +00:00
committed by GitHub
11 changed files with 88 additions and 69 deletions

7
.gitignore vendored
View File

@@ -7,3 +7,10 @@ coverage
stunnel.conf
stunnel.pid
*.out
package-lock.json
# IntelliJ IDEs
.idea
# VisualStudioCode IDEs
.vscode
.vs

View File

@@ -9,12 +9,22 @@ addons:
packages:
- g++-4.8
node_js:
- "0.10"
- "0.12"
- "4"
- "6"
- "8"
- "12"
- "13"
before_install:
- if [[ ! -f stunnel.tar.gz ]]; then wget -O stunnel.tar.gz ftp://ftp.stunnel.org/stunnel/archive/5.x/stunnel-5.54.tar.gz; fi
- if [[ ! -f ./stunnel-5.54/configure ]]; then tar -xzf stunnel.tar.gz; fi
- if [[ ! -f ./stunnel-5.54/src/stunnel ]]; then cd ./stunnel-5.54; ./configure; make; cd ..; fi
- export PATH="$PATH:$(pwd)/stunnel-5.54/src"
cache:
directories:
- '$TRAVIS_BUILD_DIR/stunnel-5.54'
after_success: npm run coveralls
before_script:
# Add an IPv6 config - see the corresponding Travis issue

View File

@@ -3,12 +3,12 @@
# Test against these versions of Node.js.
environment:
matrix:
- nodejs_version: "0.10"
- nodejs_version: "0.12"
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "8"
- nodejs_version: "12"
- nodejs_version: "10"
# - nodejs_version: "12"
# - nodejs_version: "13"
pull_requests:
do_not_increment_build_number: true

View File

@@ -20,11 +20,6 @@ var SUBSCRIBE_COMMANDS = {
punsubscribe: true
};
// Newer Node.js versions > 0.10 return the EventEmitter right away and using .EventEmitter was deprecated
if (typeof EventEmitter !== 'function') {
EventEmitter = EventEmitter.EventEmitter;
}
function noop () {}
function handle_detect_buffers_reply (reply, command, buffer_args) {
@@ -153,7 +148,6 @@ function RedisClient (options, stream) {
this.server_info = {};
this.auth_pass = options.auth_pass || options.password;
this.selected_db = options.db; // Save the selected db here, used when reconnecting
this.old_state = null;
this.fire_strings = true; // Determine if strings or buffers should be written to the stream
this.pipeline = false;
this.sub_commands_left = 0;
@@ -175,12 +169,6 @@ function RedisClient (options, stream) {
'If you want to keep on listening to this event please listen to the stream drain event directly.'
);
} else if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) {
if (this.reply_parser.name !== 'javascript') {
return this.warn(
'You attached the "' + event + '" listener without the returnBuffers option set to true.\n' +
'Please use the JavaScript parser or set the returnBuffers option to true to return buffers.'
);
}
this.reply_parser.optionReturnBuffers = true;
this.message_buffers = true;
this.handle_reply = handle_detect_buffers_reply;
@@ -216,7 +204,6 @@ function create_parser (self) {
self.create_stream();
},
returnBuffers: self.buffers || self.message_buffers,
name: self.options.parser || 'javascript',
stringNumbers: self.options.string_numbers || false
});
}

View File

@@ -4,18 +4,6 @@ var commands = require('redis-commands');
var Multi = require('./multi');
var RedisClient = require('../').RedisClient;
var Command = require('./command');
// Feature detect if a function may change it's name
var changeFunctionName = (function () {
var fn = function abc () {};
try {
Object.defineProperty(fn, 'name', {
value: 'foobar'
});
return true;
} catch (e) {
return false;
}
}());
var addCommand = function (command) {
// Some rare Redis commands use special characters in their command name
@@ -61,11 +49,9 @@ var addCommand = function (command) {
if (commandName !== command) {
RedisClient.prototype[commandName.toUpperCase()] = RedisClient.prototype[commandName] = RedisClient.prototype[command];
}
if (changeFunctionName) {
Object.defineProperty(RedisClient.prototype[command], 'name', {
value: commandName
});
}
Object.defineProperty(RedisClient.prototype[command], 'name', {
value: commandName
});
}
// Do not override existing functions
@@ -108,11 +94,9 @@ var addCommand = function (command) {
if (commandName !== command) {
Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command];
}
if (changeFunctionName) {
Object.defineProperty(Multi.prototype[command], 'name', {
value: commandName
});
}
Object.defineProperty(Multi.prototype[command], 'name', {
value: commandName
});
}
};

View File

@@ -25,13 +25,13 @@
"compare": "node benchmarks/diff_multi_bench_output.js beforeBench.txt afterBench.txt"
},
"dependencies": {
"denque": "^1.2.3",
"denque": "^1.4.1",
"redis-commands": "^1.5.0",
"redis-errors": "^1.2.0",
"redis-parser": "^3.0.0"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4.0.0"
},
"devDependencies": {
"bluebird": "^3.0.2",

View File

@@ -401,10 +401,22 @@ describe('connection tests', function () {
connect_timeout: 1000
});
process.nextTick(function () {
assert.strictEqual(client.stream._idleTimeout, 1000);
// node > 4
var timeout = client.stream.timeout;
// node <= 4
if (timeout === undefined) timeout = client.stream._idleTimeout;
assert.strictEqual(timeout, 1000);
});
client.on('connect', function () {
assert.strictEqual(client.stream._idleTimeout, -1);
// node > 4
var expected = 0;
var timeout = client.stream.timeout;
// node <= 4
if (timeout === undefined) {
timeout = client.stream._idleTimeout;
expected = -1;
}
assert.strictEqual(timeout, expected);
assert.strictEqual(client.stream.listeners('timeout').length, 0);
client.on('ready', done);
});

View File

@@ -163,11 +163,6 @@ module.exports = {
}
var parsers = ['javascript'];
var protocols = ['IPv4'];
// The js parser works the same as the hiredis parser, just activate this if you want to be on the safe side
// try {
// require('hiredis');
// parsers.push('hiredis');
// } catch (e) {/* ignore eslint */}
if (process.platform !== 'win32') {
protocols.push('IPv6', '/tmp/redis.sock');
}

View File

@@ -2,6 +2,7 @@
var assert = require('assert');
var fs = require('fs');
var util = require('util');
var path = require('path');
var intercept = require('intercept-stdout');
var config = require('./lib/config');
@@ -359,7 +360,11 @@ describe('The node_redis client', function () {
it('send_command with callback as args', function (done) {
client.send_command('abcdef', function (err, res) {
assert.strictEqual(err.message, 'ERR unknown command `abcdef`, with args beginning with: ');
if (process.platform === 'win32') {
assert.strictEqual(err.message, 'ERR unknown command `abcdef`');
} else {
assert.strictEqual(err.message, 'ERR unknown command `abcdef`, with args beginning with: ');
}
done();
});
});
@@ -675,15 +680,21 @@ describe('The node_redis client', function () {
done();
});
});
require('domain').create();
});
it('catches all errors from within the domain', function (done) {
var domain = require('domain').create();
domain.run(function () {
// Trigger an error within the domain
if (process.versions.node.split('.')[0] >= 13) {
// Node >= 13
// 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 = redis.createClient();
}
client.end(true);
// Trigger an error within the domain
client.set('domain', 'value');
});
@@ -986,7 +997,14 @@ describe('The node_redis client', function () {
}
} else {
assert.equal(err.code, 'ECONNREFUSED');
assert.equal(err.errno, 'ECONNREFUSED');
if (typeof err.errno === 'number') {
// >= Node 13
assert.equal(util.getSystemErrorName(err.errno), 'ECONNREFUSED');
} else {
// < Node 13
assert.equal(err.errno, 'ECONNREFUSED');
}
assert.equal(err.syscall, 'connect');
}
});
@@ -1046,7 +1064,13 @@ describe('The node_redis client', function () {
end();
} else {
assert.equal(err.code, 'ECONNREFUSED');
assert.equal(err.errno, 'ECONNREFUSED');
if (typeof err.errno === 'number') {
// >= Node 13
assert.equal(util.getSystemErrorName(err.errno), 'ECONNREFUSED');
} else {
// < Node 13
assert.equal(err.errno, 'ECONNREFUSED');
}
assert.equal(err.syscall, 'connect');
end();
}
@@ -1132,7 +1156,13 @@ describe('The node_redis client', function () {
end();
} else {
assert.equal(err.code, 'ECONNREFUSED');
assert.equal(err.errno, 'ECONNREFUSED');
if (typeof err.errno === 'number') {
// >= Node 13
assert.equal(util.getSystemErrorName(err.errno), 'ECONNREFUSED');
} else {
// < Node 13
assert.equal(err.errno, 'ECONNREFUSED');
}
assert.equal(err.syscall, 'connect');
redis.debug_mode = false;
client.end(true);

View File

@@ -515,8 +515,8 @@ describe('publish/subscribe', function () {
sub.stream.once('data', function () {
assert.strictEqual(sub.message_buffers, false);
assert.strictEqual(sub.shouldBuffer, false);
sub.on('pmessageBuffer', function (pattern, channel, message) {
if (parser !== 'javascript' && typeof pattern === 'string') {
sub.on('pmessageBuffer', function (pattern, channel) {
if (typeof pattern === 'string') {
pattern = new Buffer(pattern);
channel = new Buffer(channel);
}
@@ -524,10 +524,8 @@ describe('publish/subscribe', function () {
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
sub.quit(end);
});
if (parser === 'javascript') {
assert.notStrictEqual(sub.message_buffers, sub.buffers);
}
// Either message_buffers or buffers has to be true, but not both at the same time
assert.notStrictEqual(sub.message_buffers, sub.buffers);
});
var batch = sub.batch();
batch.psubscribe('*');

View File

@@ -19,9 +19,6 @@ var tls_port = 6380;
// Use skip instead of returning to indicate what tests really got skipped
var skip = false;
// Wait until stunnel4 is in the travis whitelist
// Check: https://github.com/travis-ci/apt-package-whitelist/issues/403
// If this is merged, remove the travis env checks
describe('TLS connection tests', function () {
before(function (done) {
@@ -29,9 +26,6 @@ describe('TLS connection tests', function () {
if (process.platform === 'win32') {
skip = true;
console.warn('\nStunnel tests do not work on windows atm. If you think you can fix that, it would be warmly welcome.\n');
} else if (process.env.TRAVIS === 'true') {
skip = true;
console.warn('\nTravis does not support stunnel right now. Skipping tests.\nCheck: https://github.com/travis-ci/apt-package-whitelist/issues/403\n');
}
if (skip) return done();
helper.stopStunnel(function () {
@@ -58,7 +52,7 @@ describe('TLS connection tests', function () {
client = redis.createClient({
connect_timeout: connect_timeout,
port: tls_port,
tls: tls_options
tls: utils.clone(tls_options)
});
var time = 0;
assert.strictEqual(client.address, '127.0.0.1:' + tls_port);
@@ -109,12 +103,14 @@ describe('TLS connection tests', function () {
client.get('foo', helper.isString('bar', done));
});
describe('using rediss as url protocol', function (done) {
describe('using rediss as url protocol', function () {
var tls_connect = tls.connect;
beforeEach(function () {
tls.connect = function (options) {
options = utils.clone(options);
options.ca = tls_options.ca;
options.servername = 'redis.js.org';
options.rejectUnauthorized = true;
return tls_connect.call(tls, options);
};
});