Skip to content

Commit aca53de

Browse files
authored
tests: fix CI failures
2 parents 1f5555d + feb4652 commit aca53de

File tree

11 files changed

+88
-69
lines changed

11 files changed

+88
-69
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ coverage
77
stunnel.conf
88
stunnel.pid
99
*.out
10+
package-lock.json
11+
12+
# IntelliJ IDEs
13+
.idea
14+
# VisualStudioCode IDEs
15+
.vscode
16+
.vs

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ addons:
99
packages:
1010
- g++-4.8
1111
node_js:
12-
- "0.10"
13-
- "0.12"
1412
- "4"
1513
- "6"
1614
- "8"
1715
- "12"
16+
- "13"
17+
18+
before_install:
19+
- 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
20+
- if [[ ! -f ./stunnel-5.54/configure ]]; then tar -xzf stunnel.tar.gz; fi
21+
- if [[ ! -f ./stunnel-5.54/src/stunnel ]]; then cd ./stunnel-5.54; ./configure; make; cd ..; fi
22+
- export PATH="$PATH:$(pwd)/stunnel-5.54/src"
23+
24+
cache:
25+
directories:
26+
- '$TRAVIS_BUILD_DIR/stunnel-5.54'
27+
1828
after_success: npm run coveralls
1929
before_script:
2030
# Add an IPv6 config - see the corresponding Travis issue

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
# Test against these versions of Node.js.
44
environment:
55
matrix:
6-
- nodejs_version: "0.10"
7-
- nodejs_version: "0.12"
86
- nodejs_version: "4"
97
- nodejs_version: "6"
108
- nodejs_version: "8"
11-
- nodejs_version: "12"
9+
- nodejs_version: "10"
10+
# - nodejs_version: "12"
11+
# - nodejs_version: "13"
1212

1313
pull_requests:
1414
do_not_increment_build_number: true

index.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ var SUBSCRIBE_COMMANDS = {
2020
punsubscribe: true
2121
};
2222

23-
// Newer Node.js versions > 0.10 return the EventEmitter right away and using .EventEmitter was deprecated
24-
if (typeof EventEmitter !== 'function') {
25-
EventEmitter = EventEmitter.EventEmitter;
26-
}
27-
2823
function noop () {}
2924

3025
function handle_detect_buffers_reply (reply, command, buffer_args) {
@@ -153,7 +148,6 @@ function RedisClient (options, stream) {
153148
this.server_info = {};
154149
this.auth_pass = options.auth_pass || options.password;
155150
this.selected_db = options.db; // Save the selected db here, used when reconnecting
156-
this.old_state = null;
157151
this.fire_strings = true; // Determine if strings or buffers should be written to the stream
158152
this.pipeline = false;
159153
this.sub_commands_left = 0;
@@ -175,12 +169,6 @@ function RedisClient (options, stream) {
175169
'If you want to keep on listening to this event please listen to the stream drain event directly.'
176170
);
177171
} else if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) {
178-
if (this.reply_parser.name !== 'javascript') {
179-
return this.warn(
180-
'You attached the "' + event + '" listener without the returnBuffers option set to true.\n' +
181-
'Please use the JavaScript parser or set the returnBuffers option to true to return buffers.'
182-
);
183-
}
184172
this.reply_parser.optionReturnBuffers = true;
185173
this.message_buffers = true;
186174
this.handle_reply = handle_detect_buffers_reply;
@@ -216,7 +204,6 @@ function create_parser (self) {
216204
self.create_stream();
217205
},
218206
returnBuffers: self.buffers || self.message_buffers,
219-
name: self.options.parser || 'javascript',
220207
stringNumbers: self.options.string_numbers || false
221208
});
222209
}

lib/commands.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ var commands = require('redis-commands');
44
var Multi = require('./multi');
55
var RedisClient = require('../').RedisClient;
66
var Command = require('./command');
7-
// Feature detect if a function may change it's name
8-
var changeFunctionName = (function () {
9-
var fn = function abc () {};
10-
try {
11-
Object.defineProperty(fn, 'name', {
12-
value: 'foobar'
13-
});
14-
return true;
15-
} catch (e) {
16-
return false;
17-
}
18-
}());
197

208
var addCommand = function (command) {
219
// Some rare Redis commands use special characters in their command name
@@ -61,11 +49,9 @@ var addCommand = function (command) {
6149
if (commandName !== command) {
6250
RedisClient.prototype[commandName.toUpperCase()] = RedisClient.prototype[commandName] = RedisClient.prototype[command];
6351
}
64-
if (changeFunctionName) {
65-
Object.defineProperty(RedisClient.prototype[command], 'name', {
66-
value: commandName
67-
});
68-
}
52+
Object.defineProperty(RedisClient.prototype[command], 'name', {
53+
value: commandName
54+
});
6955
}
7056

7157
// Do not override existing functions
@@ -108,11 +94,9 @@ var addCommand = function (command) {
10894
if (commandName !== command) {
10995
Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command];
11096
}
111-
if (changeFunctionName) {
112-
Object.defineProperty(Multi.prototype[command], 'name', {
113-
value: commandName
114-
});
115-
}
97+
Object.defineProperty(Multi.prototype[command], 'name', {
98+
value: commandName
99+
});
116100
}
117101
};
118102

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
"compare": "node benchmarks/diff_multi_bench_output.js beforeBench.txt afterBench.txt"
2626
},
2727
"dependencies": {
28-
"denque": "^1.2.3",
28+
"denque": "^1.4.1",
2929
"redis-commands": "^1.5.0",
3030
"redis-errors": "^1.2.0",
3131
"redis-parser": "^3.0.0"
3232
},
3333
"engines": {
34-
"node": ">=0.10.0"
34+
"node": ">=4.0.0"
3535
},
3636
"devDependencies": {
3737
"bluebird": "^3.0.2",

test/connection.spec.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,22 @@ describe('connection tests', function () {
401401
connect_timeout: 1000
402402
});
403403
process.nextTick(function () {
404-
assert.strictEqual(client.stream._idleTimeout, 1000);
404+
// node > 4
405+
var timeout = client.stream.timeout;
406+
// node <= 4
407+
if (timeout === undefined) timeout = client.stream._idleTimeout;
408+
assert.strictEqual(timeout, 1000);
405409
});
406410
client.on('connect', function () {
407-
assert.strictEqual(client.stream._idleTimeout, -1);
411+
// node > 4
412+
var expected = 0;
413+
var timeout = client.stream.timeout;
414+
// node <= 4
415+
if (timeout === undefined) {
416+
timeout = client.stream._idleTimeout;
417+
expected = -1;
418+
}
419+
assert.strictEqual(timeout, expected);
408420
assert.strictEqual(client.stream.listeners('timeout').length, 0);
409421
client.on('ready', done);
410422
});

test/helper.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ module.exports = {
163163
}
164164
var parsers = ['javascript'];
165165
var protocols = ['IPv4'];
166-
// The js parser works the same as the hiredis parser, just activate this if you want to be on the safe side
167-
// try {
168-
// require('hiredis');
169-
// parsers.push('hiredis');
170-
// } catch (e) {/* ignore eslint */}
171166
if (process.platform !== 'win32') {
172167
protocols.push('IPv6', '/tmp/redis.sock');
173168
}

test/node_redis.spec.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var assert = require('assert');
44
var fs = require('fs');
5+
var util = require('util');
56
var path = require('path');
67
var intercept = require('intercept-stdout');
78
var config = require('./lib/config');
@@ -359,7 +360,11 @@ describe('The node_redis client', function () {
359360

360361
it('send_command with callback as args', function (done) {
361362
client.send_command('abcdef', function (err, res) {
362-
assert.strictEqual(err.message, 'ERR unknown command `abcdef`, with args beginning with: ');
363+
if (process.platform === 'win32') {
364+
assert.strictEqual(err.message, 'ERR unknown command `abcdef`');
365+
} else {
366+
assert.strictEqual(err.message, 'ERR unknown command `abcdef`, with args beginning with: ');
367+
}
363368
done();
364369
});
365370
});
@@ -675,15 +680,21 @@ describe('The node_redis client', function () {
675680
done();
676681
});
677682
});
678-
require('domain').create();
679683
});
680684

681685
it('catches all errors from within the domain', function (done) {
682686
var domain = require('domain').create();
683687

684688
domain.run(function () {
685-
// Trigger an error within the domain
689+
if (process.versions.node.split('.')[0] >= 13) {
690+
// Node >= 13
691+
// Recreate client in domain so error handlers run this domain
692+
// Changed in: "error handler runs outside of its domain"
693+
// https://github.com/nodejs/node/pull/26211
694+
client = redis.createClient();
695+
}
686696
client.end(true);
697+
// Trigger an error within the domain
687698
client.set('domain', 'value');
688699
});
689700

@@ -986,7 +997,14 @@ describe('The node_redis client', function () {
986997
}
987998
} else {
988999
assert.equal(err.code, 'ECONNREFUSED');
989-
assert.equal(err.errno, 'ECONNREFUSED');
1000+
1001+
if (typeof err.errno === 'number') {
1002+
// >= Node 13
1003+
assert.equal(util.getSystemErrorName(err.errno), 'ECONNREFUSED');
1004+
} else {
1005+
// < Node 13
1006+
assert.equal(err.errno, 'ECONNREFUSED');
1007+
}
9901008
assert.equal(err.syscall, 'connect');
9911009
}
9921010
});
@@ -1046,7 +1064,13 @@ describe('The node_redis client', function () {
10461064
end();
10471065
} else {
10481066
assert.equal(err.code, 'ECONNREFUSED');
1049-
assert.equal(err.errno, 'ECONNREFUSED');
1067+
if (typeof err.errno === 'number') {
1068+
// >= Node 13
1069+
assert.equal(util.getSystemErrorName(err.errno), 'ECONNREFUSED');
1070+
} else {
1071+
// < Node 13
1072+
assert.equal(err.errno, 'ECONNREFUSED');
1073+
}
10501074
assert.equal(err.syscall, 'connect');
10511075
end();
10521076
}
@@ -1132,7 +1156,13 @@ describe('The node_redis client', function () {
11321156
end();
11331157
} else {
11341158
assert.equal(err.code, 'ECONNREFUSED');
1135-
assert.equal(err.errno, 'ECONNREFUSED');
1159+
if (typeof err.errno === 'number') {
1160+
// >= Node 13
1161+
assert.equal(util.getSystemErrorName(err.errno), 'ECONNREFUSED');
1162+
} else {
1163+
// < Node 13
1164+
assert.equal(err.errno, 'ECONNREFUSED');
1165+
}
11361166
assert.equal(err.syscall, 'connect');
11371167
redis.debug_mode = false;
11381168
client.end(true);

test/pubsub.spec.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,17 @@ describe('publish/subscribe', function () {
515515
sub.stream.once('data', function () {
516516
assert.strictEqual(sub.message_buffers, false);
517517
assert.strictEqual(sub.shouldBuffer, false);
518-
sub.on('pmessageBuffer', function (pattern, channel, message) {
519-
if (parser !== 'javascript' && typeof pattern === 'string') {
518+
sub.on('pmessageBuffer', function (pattern, channel) {
519+
if (typeof pattern === 'string') {
520520
pattern = new Buffer(pattern);
521521
channel = new Buffer(channel);
522522
}
523523
assert.strictEqual(pattern.inspect(), new Buffer('*').inspect());
524524
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
525525
sub.quit(end);
526526
});
527-
if (parser === 'javascript') {
528-
assert.notStrictEqual(sub.message_buffers, sub.buffers);
529-
}
530-
527+
// Either message_buffers or buffers has to be true, but not both at the same time
528+
assert.notStrictEqual(sub.message_buffers, sub.buffers);
531529
});
532530
var batch = sub.batch();
533531
batch.psubscribe('*');

0 commit comments

Comments
 (0)