You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
making an attempt to improve the test suite
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
examples/
|
||||
benches/
|
||||
test.js
|
||||
test/
|
||||
diff_multi_bench_output.js
|
||||
generate_commands.js
|
||||
multi_bench.js
|
||||
|
7
.travis.yml
Normal file
7
.travis.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
after_success: npm run coverage
|
@@ -46,7 +46,7 @@ Queue.prototype.forEach = function (fn, thisv) {
|
||||
Queue.prototype.getLength = function () {
|
||||
return this.head.length - this.offset + this.tail.length;
|
||||
};
|
||||
|
||||
|
||||
Object.defineProperty(Queue.prototype, "length", {
|
||||
get: function () {
|
||||
return this.getLength();
|
||||
|
12
package.json
12
package.json
@@ -3,20 +3,22 @@
|
||||
"version": "0.12.1",
|
||||
"description": "Redis client library",
|
||||
"keywords": [
|
||||
"redis",
|
||||
"database"
|
||||
"database",
|
||||
"redis"
|
||||
],
|
||||
"author": "Matt Ranney <mjr@ranney.com>",
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"scripts": {
|
||||
"test": "node ./test.js",
|
||||
"coverage": "nyc npm test && nyc report"
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"test": "nyc ./test/run.sh"
|
||||
},
|
||||
"devDependencies": {
|
||||
"colors": "~0.6.0-1",
|
||||
"coveralls": "^2.11.2",
|
||||
"hiredis": "^0.4.0",
|
||||
"metrics": ">=0.1.5",
|
||||
"nyc": "^2.2.0",
|
||||
"nyc": "^3.0.0",
|
||||
"underscore": "~1.4.4"
|
||||
},
|
||||
"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
|
||||
var PORT = process.argv[2] || 6379;
|
||||
var HOST = process.argv[3] || '127.0.0.1';
|
||||
@@ -9,4 +9,4 @@ c.info(function (err, reply) {
|
||||
if (err) process.exit(-1)
|
||||
if (!reply.length) process.exit(-1)
|
||||
process.stdout.write(reply.length.toString())
|
||||
})
|
||||
})
|
@@ -1,15 +1,16 @@
|
||||
/*global require console setTimeout process Buffer */
|
||||
var PORT = 6379;
|
||||
var HOST = '127.0.0.1';
|
||||
var parser = process.argv[3];
|
||||
|
||||
var redis = require("./index"),
|
||||
client = redis.createClient(PORT, HOST),
|
||||
client2 = redis.createClient(PORT, HOST),
|
||||
client3 = redis.createClient(PORT, HOST),
|
||||
bclient = redis.createClient(PORT, HOST, { return_buffers: true }),
|
||||
var redis = require("../index"),
|
||||
client = redis.createClient(PORT, HOST, { parser: parser }),
|
||||
client2 = redis.createClient(PORT, HOST, { parser: parser }),
|
||||
client3 = redis.createClient(PORT, HOST, { parser: parser }),
|
||||
bclient = redis.createClient(PORT, HOST, { return_buffers: true, parser: parser }),
|
||||
assert = require("assert"),
|
||||
crypto = require("crypto"),
|
||||
util = require("./lib/util"),
|
||||
util = require("../lib/util"),
|
||||
fork = require("child_process").fork,
|
||||
test_db_num = 15, // this DB will be flushed and used for testing
|
||||
tests = {},
|
||||
@@ -17,9 +18,8 @@ var redis = require("./index"),
|
||||
ended = false,
|
||||
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
|
||||
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) {
|
||||
// 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.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() {
|
||||
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");
|
||||
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() {
|
||||
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 () {
|
||||
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.
|
||||
// unixsocket /tmp/redis.sock
|
||||
@@ -374,7 +374,7 @@ tests.MULTI_7 = function () {
|
||||
return next(name);
|
||||
}
|
||||
|
||||
var p = require("./lib/parser/javascript");
|
||||
var p = require("../lib/parser/javascript");
|
||||
var parser = new p.Parser(false);
|
||||
var reply_count = 0;
|
||||
function check_reply(reply) {
|
||||
@@ -728,7 +728,7 @@ tests.WATCH_TRANSACTION = 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 () {
|
||||
// single Buffer or String
|
||||
@@ -795,9 +795,9 @@ tests.detect_buffers = function () {
|
||||
tests.socket_nodelay = function () {
|
||||
var name = "socket_nodelay", c1, c2, c3, ready_count = 0, quit_count = 0;
|
||||
|
||||
c1 = redis.createClient({socket_nodelay: true});
|
||||
c2 = redis.createClient({socket_nodelay: false});
|
||||
c3 = redis.createClient();
|
||||
c1 = redis.createClient({ socket_nodelay: true, parser: parser });
|
||||
c2 = redis.createClient({ socket_nodelay: false, parser: parser });
|
||||
c3 = redis.createClient({ parser: parser });
|
||||
|
||||
function quit_check() {
|
||||
quit_count++;
|
||||
@@ -1158,8 +1158,8 @@ tests.SUBSCRIBE_QUIT = function () {
|
||||
|
||||
tests.SUBSCRIBE_CLOSE_RESUBSCRIBE = function () {
|
||||
var name = "SUBSCRIBE_CLOSE_RESUBSCRIBE";
|
||||
var c1 = redis.createClient();
|
||||
var c2 = redis.createClient();
|
||||
var c1 = redis.createClient({ parser: parser });
|
||||
var c2 = redis.createClient({ parser: parser });
|
||||
var count = 0;
|
||||
|
||||
/* Create two clients. c1 subscribes to two channels, c2 will publish to them.
|
||||
@@ -1955,7 +1955,7 @@ tests.MONITOR = function () {
|
||||
return next(name);
|
||||
}
|
||||
|
||||
monitor_client = redis.createClient();
|
||||
monitor_client = redis.createClient({ parser: parser });
|
||||
monitor_client.monitor(function (err, res) {
|
||||
client.mget("some", "keys", "foo", "bar");
|
||||
client.set("json", JSON.stringify({
|
||||
@@ -2056,7 +2056,8 @@ tests.OPTIONAL_CALLBACK_UNDEFINED = function () {
|
||||
tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
|
||||
var name = "ENABLE_OFFLINE_QUEUE_TRUE";
|
||||
var cli = redis.createClient(9999, null, {
|
||||
max_attempts: 1
|
||||
max_attempts: 1,
|
||||
parser: parser
|
||||
// default :)
|
||||
// enable_offline_queue: true
|
||||
});
|
||||
@@ -2078,6 +2079,7 @@ tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
|
||||
tests.ENABLE_OFFLINE_QUEUE_FALSE = function () {
|
||||
var name = "ENABLE_OFFLINE_QUEUE_FALSE";
|
||||
var cli = redis.createClient(9999, null, {
|
||||
parser: parser,
|
||||
max_attempts: 1,
|
||||
enable_offline_queue: false
|
||||
});
|
||||
@@ -2134,7 +2136,10 @@ tests.DOMAIN = function () {
|
||||
});
|
||||
|
||||
// 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 () {
|
||||
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) {
|
||||
assert.strictEqual(null, err, name);
|
||||
assert.strictEqual("OK", res.toString(), name);
|
||||
@@ -2165,7 +2170,7 @@ tests.auth = function () {
|
||||
tests.auth2 = function () {
|
||||
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
|
||||
client4.on("ready", function () {
|
||||
@@ -2204,7 +2209,8 @@ tests.reconnectRetryMaxDelay = function() {
|
||||
name = 'reconnectRetryMaxDelay',
|
||||
reconnecting = false;
|
||||
var client = redis.createClient(PORT, HOST, {
|
||||
retry_max_delay: 1
|
||||
retry_max_delay: 1,
|
||||
parser: parser
|
||||
});
|
||||
client.on('ready', function() {
|
||||
if (!reconnecting) {
|
||||
@@ -2223,7 +2229,7 @@ tests.reconnectRetryMaxDelay = function() {
|
||||
|
||||
tests.unref = function () {
|
||||
var name = "unref";
|
||||
var external = fork("./test-unref.js");
|
||||
var external = fork("./test/test-unref.js");
|
||||
var done = false;
|
||||
external.on("close", function (code) {
|
||||
assert(code == 0, "test-unref.js failed");
|
||||
@@ -2235,9 +2241,12 @@ tests.unref = function () {
|
||||
}
|
||||
assert(done, "test-unref.js didn't finish in time.");
|
||||
next(name);
|
||||
}, 500);
|
||||
}, 1500);
|
||||
};
|
||||
|
||||
// starting to split tests into multiple files.
|
||||
require('./queue-test')(tests, next)
|
||||
|
||||
all_tests = Object.keys(tests);
|
||||
all_start = new Date();
|
||||
test_count = 0;
|
Reference in New Issue
Block a user