You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-10 11:43:01 +03:00
Merge pull request #776 from NodeRedis/test-tweaks
various fixes to tests, along with groundwork for adding travis and coveralls support
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
examples/
|
examples/
|
||||||
benches/
|
benches/
|
||||||
test.js
|
test/
|
||||||
diff_multi_bench_output.js
|
diff_multi_bench_output.js
|
||||||
generate_commands.js
|
generate_commands.js
|
||||||
multi_bench.js
|
multi_bench.js
|
||||||
|
11
.travis.yml
Normal file
11
.travis.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
language: node_js
|
||||||
|
sudo: true
|
||||||
|
node_js:
|
||||||
|
- "0.10"
|
||||||
|
- "0.12"
|
||||||
|
- "iojs"
|
||||||
|
before_install:
|
||||||
|
- 'printf ''bind ::1 127.0.0.1\nunixsocket /tmp/redis.sock\ndaemonize yes\nunixsocketperm 777'' >> /tmp/redis.conf'
|
||||||
|
before_script:
|
||||||
|
- sudo redis-server /tmp/redis.conf
|
||||||
|
after_success: npm run coverage
|
@@ -1,6 +1,9 @@
|
|||||||
redis - a node.js redis client
|
redis - a node.js redis client
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
[](https://travis-ci.org/NodeRedis/node_redis)
|
||||||
|
[](https://coveralls.io/r/NodeRedis/node_redis?branch=)
|
||||||
|
|
||||||
This is a complete Redis client for node.js. It supports all Redis commands,
|
This is a complete Redis client for node.js. It supports all Redis commands,
|
||||||
including many recently added commands like EVAL from experimental Redis server
|
including many recently added commands like EVAL from experimental Redis server
|
||||||
branches.
|
branches.
|
||||||
@@ -162,7 +165,7 @@ every command on a client.
|
|||||||
* `socket_nodelay`: defaults to `true`. Whether to call setNoDelay() on the TCP stream, which disables the
|
* `socket_nodelay`: defaults to `true`. Whether to call setNoDelay() on the TCP stream, which disables the
|
||||||
Nagle algorithm on the underlying socket. Setting this option to `false` can result in additional throughput at the
|
Nagle algorithm on the underlying socket. Setting this option to `false` can result in additional throughput at the
|
||||||
cost of more latency. Most applications will want this set to `true`.
|
cost of more latency. Most applications will want this set to `true`.
|
||||||
* `socket_keepalive` defaults to `true`. Whether the keep-alive functionality is enabled on the underlying socket.
|
* `socket_keepalive` defaults to `true`. Whether the keep-alive functionality is enabled on the underlying socket.
|
||||||
* `no_ready_check`: defaults to `false`. When a connection is established to the Redis server, the server might still
|
* `no_ready_check`: defaults to `false`. When a connection is established to the Redis server, the server might still
|
||||||
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
|
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
|
||||||
`node_redis` has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command
|
`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
|
|||||||
* `max_attempts` defaults to `null`. By default client will try reconnecting until connected. Setting `max_attempts`
|
* `max_attempts` defaults to `null`. By default client will try reconnecting until connected. Setting `max_attempts`
|
||||||
limits total amount of reconnects.
|
limits total amount of reconnects.
|
||||||
* `auth_pass` defaults to `null`. By default client will try connecting without auth. If set, client will run redis auth command on connect.
|
* `auth_pass` defaults to `null`. By default client will try connecting without auth. If set, client will run redis auth command on connect.
|
||||||
* `family` defaults to `IPv4`. The client connects in IPv4 if not specified or if the DNS resolution returns an IPv4 address.
|
* `family` defaults to `IPv4`. The client connects in IPv4 if not specified or if the DNS resolution returns an IPv4 address.
|
||||||
You can force an IPv6 if you set the family to 'IPv6'. See nodejs net or dns modules how to use the family type.
|
You can force an IPv6 if you set the family to 'IPv6'. See nodejs net or dns modules how to use the family type.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var redis = require("redis"),
|
var redis = require("redis"),
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
* Refactor tests, and improve test coverage (Ben Coe)
|
||||||
* Fix extraneous error output due to pubsub tests (Mikael Kohlmyr)
|
* Fix extraneous error output due to pubsub tests (Mikael Kohlmyr)
|
||||||
|
|
||||||
## v0.12.1 - Aug 10, 2014
|
## v0.12.1 - Aug 10, 2014
|
||||||
|
@@ -46,7 +46,7 @@ Queue.prototype.forEach = function (fn, thisv) {
|
|||||||
Queue.prototype.getLength = function () {
|
Queue.prototype.getLength = function () {
|
||||||
return this.head.length - this.offset + this.tail.length;
|
return this.head.length - this.offset + this.tail.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(Queue.prototype, "length", {
|
Object.defineProperty(Queue.prototype, "length", {
|
||||||
get: function () {
|
get: function () {
|
||||||
return this.getLength();
|
return this.getLength();
|
||||||
|
12
package.json
12
package.json
@@ -3,20 +3,22 @@
|
|||||||
"version": "0.12.1",
|
"version": "0.12.1",
|
||||||
"description": "Redis client library",
|
"description": "Redis client library",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"redis",
|
"database",
|
||||||
"database"
|
"redis"
|
||||||
],
|
],
|
||||||
"author": "Matt Ranney <mjr@ranney.com>",
|
"author": "Matt Ranney <mjr@ranney.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node ./test.js",
|
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||||
"coverage": "nyc npm test && nyc report"
|
"test": "nyc ./test/run.sh"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"colors": "~0.6.0-1",
|
"colors": "~0.6.0-1",
|
||||||
|
"coveralls": "^2.11.2",
|
||||||
|
"hiredis": "^0.4.0",
|
||||||
"metrics": ">=0.1.5",
|
"metrics": ">=0.1.5",
|
||||||
"nyc": "^2.2.0",
|
"nyc": "^3.0.0",
|
||||||
"underscore": "~1.4.4"
|
"underscore": "~1.4.4"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
35
test/queue-test.js
Normal file
35
test/queue-test.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
var assert = require("assert");
|
||||||
|
var Queue = require('../lib/queue');
|
||||||
|
|
||||||
|
module.exports = function (tests, next) {
|
||||||
|
var q = new Queue();
|
||||||
|
|
||||||
|
tests.push = function () {
|
||||||
|
q.push('a');
|
||||||
|
q.push(3);
|
||||||
|
assert.equal(q.length, 2);
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
tests.shift = function () {
|
||||||
|
assert.equal(q.shift(), 'a');
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
tests.forEach = function () {
|
||||||
|
q.forEach(function (v) {
|
||||||
|
assert.equal(v, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
tests.forEachWithScope = function () {
|
||||||
|
q.forEach(function (v) {
|
||||||
|
assert.equal(this.foo, 'bar');
|
||||||
|
assert.equal(v, 3);
|
||||||
|
}, {foo: 'bar'});
|
||||||
|
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
}
|
4
test/run.sh
Executable file
4
test/run.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
node ./test/test.js false hiredis
|
||||||
|
node ./test/test.js false javascript
|
@@ -1,4 +1,4 @@
|
|||||||
var redis = require("./")
|
var redis = require("../")
|
||||||
//redis.debug_mode = true
|
//redis.debug_mode = true
|
||||||
var PORT = process.argv[2] || 6379;
|
var PORT = process.argv[2] || 6379;
|
||||||
var HOST = process.argv[3] || '127.0.0.1';
|
var HOST = process.argv[3] || '127.0.0.1';
|
||||||
@@ -9,4 +9,4 @@ c.info(function (err, reply) {
|
|||||||
if (err) process.exit(-1)
|
if (err) process.exit(-1)
|
||||||
if (!reply.length) process.exit(-1)
|
if (!reply.length) process.exit(-1)
|
||||||
process.stdout.write(reply.length.toString())
|
process.stdout.write(reply.length.toString())
|
||||||
})
|
})
|
@@ -1,15 +1,16 @@
|
|||||||
/*global require console setTimeout process Buffer */
|
/*global require console setTimeout process Buffer */
|
||||||
var PORT = 6379;
|
var PORT = 6379;
|
||||||
var HOST = '127.0.0.1';
|
var HOST = '127.0.0.1';
|
||||||
|
var parser = process.argv[3];
|
||||||
|
|
||||||
var redis = require("./index"),
|
var redis = require("../index"),
|
||||||
client = redis.createClient(PORT, HOST),
|
client = redis.createClient(PORT, HOST, { parser: parser }),
|
||||||
client2 = redis.createClient(PORT, HOST),
|
client2 = redis.createClient(PORT, HOST, { parser: parser }),
|
||||||
client3 = redis.createClient(PORT, HOST),
|
client3 = redis.createClient(PORT, HOST, { parser: parser }),
|
||||||
bclient = redis.createClient(PORT, HOST, { return_buffers: true }),
|
bclient = redis.createClient(PORT, HOST, { return_buffers: true, parser: parser }),
|
||||||
assert = require("assert"),
|
assert = require("assert"),
|
||||||
crypto = require("crypto"),
|
crypto = require("crypto"),
|
||||||
util = require("./lib/util"),
|
util = require("../lib/util"),
|
||||||
fork = require("child_process").fork,
|
fork = require("child_process").fork,
|
||||||
test_db_num = 15, // this DB will be flushed and used for testing
|
test_db_num = 15, // this DB will be flushed and used for testing
|
||||||
tests = {},
|
tests = {},
|
||||||
@@ -17,9 +18,8 @@ var redis = require("./index"),
|
|||||||
ended = false,
|
ended = false,
|
||||||
next, cur_start, run_next_test, all_tests, all_start, test_count;
|
next, cur_start, run_next_test, all_tests, all_start, test_count;
|
||||||
|
|
||||||
|
|
||||||
// Set this to truthy to see the wire protocol and other debugging info
|
// Set this to truthy to see the wire protocol and other debugging info
|
||||||
redis.debug_mode = process.argv[2];
|
redis.debug_mode = process.argv[2] ? JSON.parse(process.argv[2]) : false;
|
||||||
|
|
||||||
function server_version_at_least(connection, desired_version) {
|
function server_version_at_least(connection, desired_version) {
|
||||||
// Return true if the server version >= desired_version
|
// Return true if the server version >= desired_version
|
||||||
@@ -116,7 +116,7 @@ next = function next(name) {
|
|||||||
// Tests are run in the order they are defined, so FLUSHDB should always be first.
|
// Tests are run in the order they are defined, so FLUSHDB should always be first.
|
||||||
|
|
||||||
tests.IPV4 = function () {
|
tests.IPV4 = function () {
|
||||||
var ipv4Client = redis.createClient( PORT, "127.0.0.1", { "family" : "IPv4" } );
|
var ipv4Client = redis.createClient( PORT, "127.0.0.1", { family : "IPv4", parser: parser } );
|
||||||
|
|
||||||
ipv4Client.once("ready", function start_tests() {
|
ipv4Client.once("ready", function start_tests() {
|
||||||
console.log("Connected to " + ipv4Client.address + ", Redis server version " + ipv4Client.server_info.redis_version + "\n");
|
console.log("Connected to " + ipv4Client.address + ", Redis server version " + ipv4Client.server_info.redis_version + "\n");
|
||||||
@@ -142,7 +142,7 @@ tests.IPV6 = function () {
|
|||||||
console.log("Skipping IPV6 for old Redis server version < 2.8.0");
|
console.log("Skipping IPV6 for old Redis server version < 2.8.0");
|
||||||
return run_next_test();
|
return run_next_test();
|
||||||
}
|
}
|
||||||
var ipv6Client = redis.createClient( PORT, "::1", { "family" : "IPv6" } );
|
var ipv6Client = redis.createClient( PORT, "::1", { family: "IPv6", parser: parser } );
|
||||||
|
|
||||||
ipv6Client.once("ready", function start_tests() {
|
ipv6Client.once("ready", function start_tests() {
|
||||||
console.log("Connected to " + ipv6Client.address + ", Redis server version " + ipv6Client.server_info.redis_version + "\n");
|
console.log("Connected to " + ipv6Client.address + ", Redis server version " + ipv6Client.server_info.redis_version + "\n");
|
||||||
@@ -164,7 +164,7 @@ tests.IPV6 = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests.UNIX_SOCKET = function () {
|
tests.UNIX_SOCKET = function () {
|
||||||
var unixClient = redis.createClient('/tmp/redis.sock');
|
var unixClient = redis.createClient('/tmp/redis.sock', { parser: parser });
|
||||||
|
|
||||||
// if this fails, check the permission of unix socket.
|
// if this fails, check the permission of unix socket.
|
||||||
// unixsocket /tmp/redis.sock
|
// unixsocket /tmp/redis.sock
|
||||||
@@ -374,7 +374,7 @@ tests.MULTI_7 = function () {
|
|||||||
return next(name);
|
return next(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var p = require("./lib/parser/javascript");
|
var p = require("../lib/parser/javascript");
|
||||||
var parser = new p.Parser(false);
|
var parser = new p.Parser(false);
|
||||||
var reply_count = 0;
|
var reply_count = 0;
|
||||||
function check_reply(reply) {
|
function check_reply(reply) {
|
||||||
@@ -728,7 +728,7 @@ tests.WATCH_TRANSACTION = function () {
|
|||||||
|
|
||||||
|
|
||||||
tests.detect_buffers = function () {
|
tests.detect_buffers = function () {
|
||||||
var name = "detect_buffers", detect_client = redis.createClient({detect_buffers: true});
|
var name = "detect_buffers", detect_client = redis.createClient({ detect_buffers: true, parser: parser });
|
||||||
|
|
||||||
detect_client.on("ready", function () {
|
detect_client.on("ready", function () {
|
||||||
// single Buffer or String
|
// single Buffer or String
|
||||||
@@ -795,9 +795,9 @@ tests.detect_buffers = function () {
|
|||||||
tests.socket_nodelay = function () {
|
tests.socket_nodelay = function () {
|
||||||
var name = "socket_nodelay", c1, c2, c3, ready_count = 0, quit_count = 0;
|
var name = "socket_nodelay", c1, c2, c3, ready_count = 0, quit_count = 0;
|
||||||
|
|
||||||
c1 = redis.createClient({socket_nodelay: true});
|
c1 = redis.createClient({ socket_nodelay: true, parser: parser });
|
||||||
c2 = redis.createClient({socket_nodelay: false});
|
c2 = redis.createClient({ socket_nodelay: false, parser: parser });
|
||||||
c3 = redis.createClient();
|
c3 = redis.createClient({ parser: parser });
|
||||||
|
|
||||||
function quit_check() {
|
function quit_check() {
|
||||||
quit_count++;
|
quit_count++;
|
||||||
@@ -1158,8 +1158,8 @@ tests.SUBSCRIBE_QUIT = function () {
|
|||||||
|
|
||||||
tests.SUBSCRIBE_CLOSE_RESUBSCRIBE = function () {
|
tests.SUBSCRIBE_CLOSE_RESUBSCRIBE = function () {
|
||||||
var name = "SUBSCRIBE_CLOSE_RESUBSCRIBE";
|
var name = "SUBSCRIBE_CLOSE_RESUBSCRIBE";
|
||||||
var c1 = redis.createClient();
|
var c1 = redis.createClient({ parser: parser });
|
||||||
var c2 = redis.createClient();
|
var c2 = redis.createClient({ parser: parser });
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
|
||||||
/* Create two clients. c1 subscribes to two channels, c2 will publish to them.
|
/* Create two clients. c1 subscribes to two channels, c2 will publish to them.
|
||||||
@@ -1955,7 +1955,7 @@ tests.MONITOR = function () {
|
|||||||
return next(name);
|
return next(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
monitor_client = redis.createClient();
|
monitor_client = redis.createClient({ parser: parser });
|
||||||
monitor_client.monitor(function (err, res) {
|
monitor_client.monitor(function (err, res) {
|
||||||
client.mget("some", "keys", "foo", "bar");
|
client.mget("some", "keys", "foo", "bar");
|
||||||
client.set("json", JSON.stringify({
|
client.set("json", JSON.stringify({
|
||||||
@@ -2056,7 +2056,8 @@ tests.OPTIONAL_CALLBACK_UNDEFINED = function () {
|
|||||||
tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
|
tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
|
||||||
var name = "ENABLE_OFFLINE_QUEUE_TRUE";
|
var name = "ENABLE_OFFLINE_QUEUE_TRUE";
|
||||||
var cli = redis.createClient(9999, null, {
|
var cli = redis.createClient(9999, null, {
|
||||||
max_attempts: 1
|
max_attempts: 1,
|
||||||
|
parser: parser
|
||||||
// default :)
|
// default :)
|
||||||
// enable_offline_queue: true
|
// enable_offline_queue: true
|
||||||
});
|
});
|
||||||
@@ -2078,6 +2079,7 @@ tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
|
|||||||
tests.ENABLE_OFFLINE_QUEUE_FALSE = function () {
|
tests.ENABLE_OFFLINE_QUEUE_FALSE = function () {
|
||||||
var name = "ENABLE_OFFLINE_QUEUE_FALSE";
|
var name = "ENABLE_OFFLINE_QUEUE_FALSE";
|
||||||
var cli = redis.createClient(9999, null, {
|
var cli = redis.createClient(9999, null, {
|
||||||
|
parser: parser,
|
||||||
max_attempts: 1,
|
max_attempts: 1,
|
||||||
enable_offline_queue: false
|
enable_offline_queue: false
|
||||||
});
|
});
|
||||||
@@ -2134,7 +2136,10 @@ tests.DOMAIN = function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// this is the expected and desired behavior
|
// this is the expected and desired behavior
|
||||||
domain.on('error', function (err) { next(name); });
|
domain.on('error', function (err) {
|
||||||
|
domain.exit();
|
||||||
|
next(name);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2143,7 +2148,7 @@ tests.DOMAIN = function () {
|
|||||||
tests.auth = function () {
|
tests.auth = function () {
|
||||||
var name = "AUTH", client4, ready_count = 0;
|
var name = "AUTH", client4, ready_count = 0;
|
||||||
|
|
||||||
client4 = redis.createClient(9006, "filefish.redistogo.com");
|
client4 = redis.createClient(9006, "filefish.redistogo.com", { parser: parser });
|
||||||
client4.auth("664b1b6aaf134e1ec281945a8de702a9", function (err, res) {
|
client4.auth("664b1b6aaf134e1ec281945a8de702a9", function (err, res) {
|
||||||
assert.strictEqual(null, err, name);
|
assert.strictEqual(null, err, name);
|
||||||
assert.strictEqual("OK", res.toString(), name);
|
assert.strictEqual("OK", res.toString(), name);
|
||||||
@@ -2165,7 +2170,7 @@ tests.auth = function () {
|
|||||||
tests.auth2 = function () {
|
tests.auth2 = function () {
|
||||||
var name = "AUTH2", client4, ready_count = 0;
|
var name = "AUTH2", client4, ready_count = 0;
|
||||||
|
|
||||||
client4 = redis.createClient(9006, "filefish.redistogo.com", {auth_pass: "664b1b6aaf134e1ec281945a8de702a9"});
|
client4 = redis.createClient(9006, "filefish.redistogo.com", { auth_pass: "664b1b6aaf134e1ec281945a8de702a9", parser: parser });
|
||||||
|
|
||||||
// test auth, then kill the connection so it'll auto-reconnect and auto-re-auth
|
// test auth, then kill the connection so it'll auto-reconnect and auto-re-auth
|
||||||
client4.on("ready", function () {
|
client4.on("ready", function () {
|
||||||
@@ -2204,7 +2209,8 @@ tests.reconnectRetryMaxDelay = function() {
|
|||||||
name = 'reconnectRetryMaxDelay',
|
name = 'reconnectRetryMaxDelay',
|
||||||
reconnecting = false;
|
reconnecting = false;
|
||||||
var client = redis.createClient(PORT, HOST, {
|
var client = redis.createClient(PORT, HOST, {
|
||||||
retry_max_delay: 1
|
retry_max_delay: 1,
|
||||||
|
parser: parser
|
||||||
});
|
});
|
||||||
client.on('ready', function() {
|
client.on('ready', function() {
|
||||||
if (!reconnecting) {
|
if (!reconnecting) {
|
||||||
@@ -2223,7 +2229,7 @@ tests.reconnectRetryMaxDelay = function() {
|
|||||||
|
|
||||||
tests.unref = function () {
|
tests.unref = function () {
|
||||||
var name = "unref";
|
var name = "unref";
|
||||||
var external = fork("./test-unref.js");
|
var external = fork("./test/test-unref.js");
|
||||||
var done = false;
|
var done = false;
|
||||||
external.on("close", function (code) {
|
external.on("close", function (code) {
|
||||||
assert(code == 0, "test-unref.js failed");
|
assert(code == 0, "test-unref.js failed");
|
||||||
@@ -2235,9 +2241,12 @@ tests.unref = function () {
|
|||||||
}
|
}
|
||||||
assert(done, "test-unref.js didn't finish in time.");
|
assert(done, "test-unref.js didn't finish in time.");
|
||||||
next(name);
|
next(name);
|
||||||
}, 500);
|
}, 1500);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// starting to split tests into multiple files.
|
||||||
|
require('./queue-test')(tests, next)
|
||||||
|
|
||||||
all_tests = Object.keys(tests);
|
all_tests = Object.keys(tests);
|
||||||
all_start = new Date();
|
all_start = new Date();
|
||||||
test_count = 0;
|
test_count = 0;
|
Reference in New Issue
Block a user