Skip to content

Commit 131f92b

Browse files
committed
Merge pull request #776 from NodeRedis/test-tweaks
various fixes to tests, along with groundwork for adding travis and coveralls support
2 parents b92a62d + 96da407 commit 131f92b

File tree

10 files changed

+103
-38
lines changed

10 files changed

+103
-38
lines changed

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
examples/
22
benches/
3-
test.js
3+
test/
44
diff_multi_bench_output.js
55
generate_commands.js
66
multi_bench.js

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: node_js
2+
sudo: true
3+
node_js:
4+
- "0.10"
5+
- "0.12"
6+
- "iojs"
7+
before_install:
8+
- 'printf ''bind ::1 127.0.0.1\nunixsocket /tmp/redis.sock\ndaemonize yes\nunixsocketperm 777'' >> /tmp/redis.conf'
9+
before_script:
10+
- sudo redis-server /tmp/redis.conf
11+
after_success: npm run coverage

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
redis - a node.js redis client
22
===========================
33

4+
[![Build Status](https://travis-ci.org/NodeRedis/node_redis.png)](https://travis-ci.org/NodeRedis/node_redis)
5+
[![Coverage Status](https://coveralls.io/reposNodeRedis/node_redisbadge.svg?branch=)](https://coveralls.io/r/NodeRedis/node_redis?branch=)
6+
47
This is a complete Redis client for node.js. It supports all Redis commands,
58
including many recently added commands like EVAL from experimental Redis server
69
branches.
@@ -162,7 +165,7 @@ every command on a client.
162165
* `socket_nodelay`: defaults to `true`. Whether to call setNoDelay() on the TCP stream, which disables the
163166
Nagle algorithm on the underlying socket. Setting this option to `false` can result in additional throughput at the
164167
cost of more latency. Most applications will want this set to `true`.
165-
* `socket_keepalive` defaults to `true`. Whether the keep-alive functionality is enabled on the underlying socket.
168+
* `socket_keepalive` defaults to `true`. Whether the keep-alive functionality is enabled on the underlying socket.
166169
* `no_ready_check`: defaults to `false`. When a connection is established to the Redis server, the server might still
167170
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
168171
`node_redis` has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command
@@ -181,8 +184,8 @@ limits total time for client to reconnect. Value is provided in milliseconds and
181184
* `max_attempts` defaults to `null`. By default client will try reconnecting until connected. Setting `max_attempts`
182185
limits total amount of reconnects.
183186
* `auth_pass` defaults to `null`. By default client will try connecting without auth. If set, client will run redis auth command on connect.
184-
* `family` defaults to `IPv4`. The client connects in IPv4 if not specified or if the DNS resolution returns an IPv4 address.
185-
You can force an IPv6 if you set the family to 'IPv6'. See nodejs net or dns modules how to use the family type.
187+
* `family` defaults to `IPv4`. The client connects in IPv4 if not specified or if the DNS resolution returns an IPv4 address.
188+
You can force an IPv6 if you set the family to 'IPv6'. See nodejs net or dns modules how to use the family type.
186189

187190
```js
188191
var redis = require("redis"),

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changelog
22
=========
33

4+
* Refactor tests, and improve test coverage (Ben Coe)
45
* Fix extraneous error output due to pubsub tests (Mikael Kohlmyr)
56

67
## v0.12.1 - Aug 10, 2014

lib/queue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Queue.prototype.forEach = function (fn, thisv) {
4646
Queue.prototype.getLength = function () {
4747
return this.head.length - this.offset + this.tail.length;
4848
};
49-
49+
5050
Object.defineProperty(Queue.prototype, "length", {
5151
get: function () {
5252
return this.getLength();

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
"version": "0.12.1",
44
"description": "Redis client library",
55
"keywords": [
6-
"redis",
7-
"database"
6+
"database",
7+
"redis"
88
],
99
"author": "Matt Ranney <mjr@ranney.com>",
1010
"license": "MIT",
1111
"main": "./index.js",
1212
"scripts": {
13-
"test": "node ./test.js",
14-
"coverage": "nyc npm test && nyc report"
13+
"coverage": "nyc report --reporter=text-lcov | coveralls",
14+
"test": "nyc ./test/run.sh"
1515
},
1616
"devDependencies": {
1717
"colors": "~0.6.0-1",
18+
"coveralls": "^2.11.2",
19+
"hiredis": "^0.4.0",
1820
"metrics": ">=0.1.5",
19-
"nyc": "^2.2.0",
21+
"nyc": "^3.0.0",
2022
"underscore": "~1.4.4"
2123
},
2224
"repository": {

test/queue-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var assert = require("assert");
2+
var Queue = require('../lib/queue');
3+
4+
module.exports = function (tests, next) {
5+
var q = new Queue();
6+
7+
tests.push = function () {
8+
q.push('a');
9+
q.push(3);
10+
assert.equal(q.length, 2);
11+
return next();
12+
}
13+
14+
tests.shift = function () {
15+
assert.equal(q.shift(), 'a');
16+
return next();
17+
}
18+
19+
tests.forEach = function () {
20+
q.forEach(function (v) {
21+
assert.equal(v, 3);
22+
});
23+
24+
return next();
25+
}
26+
27+
tests.forEachWithScope = function () {
28+
q.forEach(function (v) {
29+
assert.equal(this.foo, 'bar');
30+
assert.equal(v, 3);
31+
}, {foo: 'bar'});
32+
33+
return next();
34+
}
35+
}

test/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
node ./test/test.js false hiredis
4+
node ./test/test.js false javascript

test-unref.js renamed to test/test-unref.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var redis = require("./")
1+
var redis = require("../")
22
//redis.debug_mode = true
33
var PORT = process.argv[2] || 6379;
44
var HOST = process.argv[3] || '127.0.0.1';
@@ -9,4 +9,4 @@ c.info(function (err, reply) {
99
if (err) process.exit(-1)
1010
if (!reply.length) process.exit(-1)
1111
process.stdout.write(reply.length.toString())
12-
})
12+
})

test.js renamed to test/test.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/*global require console setTimeout process Buffer */
22
var PORT = 6379;
33
var HOST = '127.0.0.1';
4+
var parser = process.argv[3];
45

5-
var redis = require("./index"),
6-
client = redis.createClient(PORT, HOST),
7-
client2 = redis.createClient(PORT, HOST),
8-
client3 = redis.createClient(PORT, HOST),
9-
bclient = redis.createClient(PORT, HOST, { return_buffers: true }),
6+
var redis = require("../index"),
7+
client = redis.createClient(PORT, HOST, { parser: parser }),
8+
client2 = redis.createClient(PORT, HOST, { parser: parser }),
9+
client3 = redis.createClient(PORT, HOST, { parser: parser }),
10+
bclient = redis.createClient(PORT, HOST, { return_buffers: true, parser: parser }),
1011
assert = require("assert"),
1112
crypto = require("crypto"),
12-
util = require("./lib/util"),
13+
util = require("../lib/util"),
1314
fork = require("child_process").fork,
1415
test_db_num = 15, // this DB will be flushed and used for testing
1516
tests = {},
1617
connected = false,
1718
ended = false,
1819
next, cur_start, run_next_test, all_tests, all_start, test_count;
1920

20-
2121
// Set this to truthy to see the wire protocol and other debugging info
22-
redis.debug_mode = process.argv[2];
22+
redis.debug_mode = process.argv[2] ? JSON.parse(process.argv[2]) : false;
2323

2424
function server_version_at_least(connection, desired_version) {
2525
// Return true if the server version >= desired_version
@@ -116,7 +116,7 @@ next = function next(name) {
116116
// Tests are run in the order they are defined, so FLUSHDB should always be first.
117117

118118
tests.IPV4 = function () {
119-
var ipv4Client = redis.createClient( PORT, "127.0.0.1", { "family" : "IPv4" } );
119+
var ipv4Client = redis.createClient( PORT, "127.0.0.1", { family : "IPv4", parser: parser } );
120120

121121
ipv4Client.once("ready", function start_tests() {
122122
console.log("Connected to " + ipv4Client.address + ", Redis server version " + ipv4Client.server_info.redis_version + "\n");
@@ -142,7 +142,7 @@ tests.IPV6 = function () {
142142
console.log("Skipping IPV6 for old Redis server version < 2.8.0");
143143
return run_next_test();
144144
}
145-
var ipv6Client = redis.createClient( PORT, "::1", { "family" : "IPv6" } );
145+
var ipv6Client = redis.createClient( PORT, "::1", { family: "IPv6", parser: parser } );
146146

147147
ipv6Client.once("ready", function start_tests() {
148148
console.log("Connected to " + ipv6Client.address + ", Redis server version " + ipv6Client.server_info.redis_version + "\n");
@@ -164,7 +164,7 @@ tests.IPV6 = function () {
164164
}
165165

166166
tests.UNIX_SOCKET = function () {
167-
var unixClient = redis.createClient('/tmp/redis.sock');
167+
var unixClient = redis.createClient('/tmp/redis.sock', { parser: parser });
168168

169169
// if this fails, check the permission of unix socket.
170170
// unixsocket /tmp/redis.sock
@@ -374,7 +374,7 @@ tests.MULTI_7 = function () {
374374
return next(name);
375375
}
376376

377-
var p = require("./lib/parser/javascript");
377+
var p = require("../lib/parser/javascript");
378378
var parser = new p.Parser(false);
379379
var reply_count = 0;
380380
function check_reply(reply) {
@@ -728,7 +728,7 @@ tests.WATCH_TRANSACTION = function () {
728728

729729

730730
tests.detect_buffers = function () {
731-
var name = "detect_buffers", detect_client = redis.createClient({detect_buffers: true});
731+
var name = "detect_buffers", detect_client = redis.createClient({ detect_buffers: true, parser: parser });
732732

733733
detect_client.on("ready", function () {
734734
// single Buffer or String
@@ -795,9 +795,9 @@ tests.detect_buffers = function () {
795795
tests.socket_nodelay = function () {
796796
var name = "socket_nodelay", c1, c2, c3, ready_count = 0, quit_count = 0;
797797

798-
c1 = redis.createClient({socket_nodelay: true});
799-
c2 = redis.createClient({socket_nodelay: false});
800-
c3 = redis.createClient();
798+
c1 = redis.createClient({ socket_nodelay: true, parser: parser });
799+
c2 = redis.createClient({ socket_nodelay: false, parser: parser });
800+
c3 = redis.createClient({ parser: parser });
801801

802802
function quit_check() {
803803
quit_count++;
@@ -1158,8 +1158,8 @@ tests.SUBSCRIBE_QUIT = function () {
11581158

11591159
tests.SUBSCRIBE_CLOSE_RESUBSCRIBE = function () {
11601160
var name = "SUBSCRIBE_CLOSE_RESUBSCRIBE";
1161-
var c1 = redis.createClient();
1162-
var c2 = redis.createClient();
1161+
var c1 = redis.createClient({ parser: parser });
1162+
var c2 = redis.createClient({ parser: parser });
11631163
var count = 0;
11641164

11651165
/* Create two clients. c1 subscribes to two channels, c2 will publish to them.
@@ -1955,7 +1955,7 @@ tests.MONITOR = function () {
19551955
return next(name);
19561956
}
19571957

1958-
monitor_client = redis.createClient();
1958+
monitor_client = redis.createClient({ parser: parser });
19591959
monitor_client.monitor(function (err, res) {
19601960
client.mget("some", "keys", "foo", "bar");
19611961
client.set("json", JSON.stringify({
@@ -2056,7 +2056,8 @@ tests.OPTIONAL_CALLBACK_UNDEFINED = function () {
20562056
tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
20572057
var name = "ENABLE_OFFLINE_QUEUE_TRUE";
20582058
var cli = redis.createClient(9999, null, {
2059-
max_attempts: 1
2059+
max_attempts: 1,
2060+
parser: parser
20602061
// default :)
20612062
// enable_offline_queue: true
20622063
});
@@ -2078,6 +2079,7 @@ tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
20782079
tests.ENABLE_OFFLINE_QUEUE_FALSE = function () {
20792080
var name = "ENABLE_OFFLINE_QUEUE_FALSE";
20802081
var cli = redis.createClient(9999, null, {
2082+
parser: parser,
20812083
max_attempts: 1,
20822084
enable_offline_queue: false
20832085
});
@@ -2134,7 +2136,10 @@ tests.DOMAIN = function () {
21342136
});
21352137

21362138
// this is the expected and desired behavior
2137-
domain.on('error', function (err) { next(name); });
2139+
domain.on('error', function (err) {
2140+
domain.exit();
2141+
next(name);
2142+
});
21382143
}
21392144
};
21402145

@@ -2143,7 +2148,7 @@ tests.DOMAIN = function () {
21432148
tests.auth = function () {
21442149
var name = "AUTH", client4, ready_count = 0;
21452150

2146-
client4 = redis.createClient(9006, "filefish.redistogo.com");
2151+
client4 = redis.createClient(9006, "filefish.redistogo.com", { parser: parser });
21472152
client4.auth("664b1b6aaf134e1ec281945a8de702a9", function (err, res) {
21482153
assert.strictEqual(null, err, name);
21492154
assert.strictEqual("OK", res.toString(), name);
@@ -2165,7 +2170,7 @@ tests.auth = function () {
21652170
tests.auth2 = function () {
21662171
var name = "AUTH2", client4, ready_count = 0;
21672172

2168-
client4 = redis.createClient(9006, "filefish.redistogo.com", {auth_pass: "664b1b6aaf134e1ec281945a8de702a9"});
2173+
client4 = redis.createClient(9006, "filefish.redistogo.com", { auth_pass: "664b1b6aaf134e1ec281945a8de702a9", parser: parser });
21692174

21702175
// test auth, then kill the connection so it'll auto-reconnect and auto-re-auth
21712176
client4.on("ready", function () {
@@ -2204,7 +2209,8 @@ tests.reconnectRetryMaxDelay = function() {
22042209
name = 'reconnectRetryMaxDelay',
22052210
reconnecting = false;
22062211
var client = redis.createClient(PORT, HOST, {
2207-
retry_max_delay: 1
2212+
retry_max_delay: 1,
2213+
parser: parser
22082214
});
22092215
client.on('ready', function() {
22102216
if (!reconnecting) {
@@ -2223,7 +2229,7 @@ tests.reconnectRetryMaxDelay = function() {
22232229

22242230
tests.unref = function () {
22252231
var name = "unref";
2226-
var external = fork("./test-unref.js");
2232+
var external = fork("./test/test-unref.js");
22272233
var done = false;
22282234
external.on("close", function (code) {
22292235
assert(code == 0, "test-unref.js failed");
@@ -2235,9 +2241,12 @@ tests.unref = function () {
22352241
}
22362242
assert(done, "test-unref.js didn't finish in time.");
22372243
next(name);
2238-
}, 500);
2244+
}, 1500);
22392245
};
22402246

2247+
// starting to split tests into multiple files.
2248+
require('./queue-test')(tests, next)
2249+
22412250
all_tests = Object.keys(tests);
22422251
all_start = new Date();
22432252
test_count = 0;

0 commit comments

Comments
 (0)