Browse Source

making an attempt to improve the test suite

gh-pages
Benjamin Coe 9 years ago
parent
commit
d30e80abbe
  1. 2
      .npmignore
  2. 7
      .travis.yml
  3. 12
      package.json
  4. 35
      test/queue-test.js
  5. 4
      test/run.sh
  6. 2
      test/test-unref.js
  7. 61
      test/test.js

2
.npmignore

@ -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

7
.travis.yml

@ -0,0 +1,7 @@
language: node_js
sudo: false
node_js:
- "0.10"
- "0.12"
- "iojs"
after_success: npm run coverage

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

@ -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

@ -0,0 +1,4 @@
#!/usr/bin/env bash
node ./test/test.js false hiredis
node ./test/test.js false javascript

2
test-unref.js → test/test-unref.js

@ -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';

61
test.js → test/test.js

@ -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;
Loading…
Cancel
Save