Skip to content

Commit

Permalink
Merge pull request redis#776 from NodeRedis/test-tweaks
Browse files Browse the repository at this point in the history
various fixes to tests, along with groundwork for adding travis and coveralls support
  • Loading branch information
bcoe committed Jul 12, 2015
2 parents b92a62d + 96da407 commit 131f92b
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
examples/
benches/
test.js
test/
diff_multi_bench_output.js
generate_commands.js
multi_bench.js
Expand Down
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
redis - a node.js redis client
===========================

[![Build Status](https://travis-ci.org/NodeRedis/node_redis.png)](https://travis-ci.org/NodeRedis/node_redis)
[![Coverage Status](https://coveralls.io/reposNodeRedis/node_redisbadge.svg?branch=)](https://coveralls.io/r/NodeRedis/node_redis?branch=)

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
branches.
Expand Down Expand Up @@ -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
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`.
* `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
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
Expand All @@ -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`
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.
* `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.
* `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.

```js
var redis = require("redis"),
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========

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

## v0.12.1 - Aug 10, 2014
Expand Down
2 changes: 1 addition & 1 deletion lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
"version": "0.12.1",
"description": "Redis client library",
"keywords": [
"redis",
"database"
"database",
"redis"
],
"author": "Matt Ranney <[email protected]>",
"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": {
Expand Down
35 changes: 35 additions & 0 deletions test/queue-test.js
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

node ./test/test.js false hiredis
node ./test/test.js false javascript
4 changes: 2 additions & 2 deletions test-unref.js → test/test-unref.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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())
})
})
61 changes: 35 additions & 26 deletions test.js → test/test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*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 = {},
connected = false,
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
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
});
Expand All @@ -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
});
Expand Down Expand Up @@ -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);
});
}
};

Expand All @@ -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);
Expand All @@ -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 () {
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand All @@ -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;
Expand Down

0 comments on commit 131f92b

Please sign in to comment.