You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Insert deprecation warnings and some minor refactoring
This commit is contained in:
@@ -4,6 +4,7 @@ var assert = require("assert");
|
||||
var config = require("../lib/config");
|
||||
var helper = require("../helper");
|
||||
var redis = config.redis;
|
||||
var intercept = require('intercept-stdout');
|
||||
|
||||
describe("The 'blpop' method", function () {
|
||||
|
||||
@@ -23,7 +24,14 @@ describe("The 'blpop' method", function () {
|
||||
it('pops value immediately if list contains values', function (done) {
|
||||
bclient = redis.createClient.apply(redis.createClient, args);
|
||||
redis.debug_mode = true;
|
||||
var text = '';
|
||||
var unhookIntercept = intercept(function(data) {
|
||||
text += data;
|
||||
return '';
|
||||
});
|
||||
client.rpush("blocking list", "initial value", helper.isNumber(1));
|
||||
unhookIntercept();
|
||||
assert(/^Send 127\.0\.0\.1:6379 id [0-9]+: \*3\r\n\$5\r\nrpush\r\n\$13\r\nblocking list\r\n\$13\r\ninitial value\r\n\n$/.test(text));
|
||||
redis.debug_mode = false;
|
||||
bclient.blpop("blocking list", 0, function (err, value) {
|
||||
assert.strictEqual(value[0], "blocking list");
|
||||
|
@@ -68,7 +68,6 @@ describe("The 'get' method", function () {
|
||||
});
|
||||
|
||||
it("gets the value correctly", function (done) {
|
||||
client.GET(key, redis.print); // Use the utility function to print the result
|
||||
client.GET(key, function (err, res) {
|
||||
helper.isString(value)(err, res);
|
||||
done(err);
|
||||
|
@@ -33,7 +33,6 @@ describe("The 'getset' method", function () {
|
||||
});
|
||||
|
||||
it("reports an error", function (done) {
|
||||
client.GET(key, redis.print); // Use the utility function to print the error
|
||||
client.get(key, function (err, res) {
|
||||
assert(err.message.match(/The connection has already been closed/));
|
||||
done();
|
||||
|
@@ -4,6 +4,7 @@ var assert = require("assert");
|
||||
var config = require("./lib/config");
|
||||
var helper = require('./helper');
|
||||
var redis = config.redis;
|
||||
var intercept = require('intercept-stdout');
|
||||
|
||||
describe("connection tests", function () {
|
||||
helper.allTests(function(parser, ip, args) {
|
||||
@@ -91,6 +92,7 @@ describe("connection tests", function () {
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
client.end(true);
|
||||
assert.strictEqual(params.times_connected, 1);
|
||||
setTimeout(done, 100);
|
||||
});
|
||||
});
|
||||
|
@@ -2,11 +2,16 @@
|
||||
|
||||
// helper to start and stop the stunnel process.
|
||||
var spawn = require('child_process').spawn;
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var EventEmitter = require('events');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
|
||||
// Newer Node.js versions > 0.10 return the EventEmitter right away and using .EventEmitter was deprecated
|
||||
if (typeof EventEmitter !== 'function') {
|
||||
EventEmitter = EventEmitter.EventEmitter;
|
||||
}
|
||||
|
||||
function once(cb) {
|
||||
var called = false;
|
||||
return function() {
|
||||
|
@@ -384,9 +384,18 @@ describe("The node_redis client", function () {
|
||||
|
||||
describe('idle', function () {
|
||||
it('emits idle as soon as there are no outstanding commands', function (done) {
|
||||
var end = helper.callFuncAfter(done, 2);
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(
|
||||
msg,
|
||||
'The idle event listener is deprecated and will likely be removed in v.3.0.0.\n' +
|
||||
'If you rely on this feature please open a new ticket in node_redis with your use case'
|
||||
);
|
||||
end();
|
||||
});
|
||||
client.on('idle', function onIdle () {
|
||||
client.removeListener("idle", onIdle);
|
||||
client.get('foo', helper.isString('bar', done));
|
||||
client.get('foo', helper.isString('bar', end));
|
||||
});
|
||||
client.set('foo', 'bar');
|
||||
});
|
||||
@@ -614,9 +623,17 @@ describe("The node_redis client", function () {
|
||||
parser: parser,
|
||||
no_ready_check: true
|
||||
});
|
||||
var end = helper.callFuncAfter(done, 2);
|
||||
var end = helper.callFuncAfter(done, 3);
|
||||
client.set('foo', 'bar');
|
||||
client.get('foo', end);
|
||||
client.on('warning', function (msg) {
|
||||
assert.strictEqual(
|
||||
msg,
|
||||
'The drain event listener is deprecated and will be removed in v.3.0.0.\n' +
|
||||
'If you want to keep on listening to this event please listen to the stream drain event directly.'
|
||||
);
|
||||
end();
|
||||
});
|
||||
client.on('drain', function() {
|
||||
assert(client.offline_queue.length === 0);
|
||||
end();
|
||||
@@ -673,6 +690,9 @@ describe("The node_redis client", function () {
|
||||
client.on('reconnecting', function(params) {
|
||||
i++;
|
||||
assert.equal(params.attempt, i);
|
||||
assert.strictEqual(params.times_connected, 0);
|
||||
assert(params.error instanceof Error);
|
||||
assert(typeof params.total_retry_time === 'number');
|
||||
assert.strictEqual(client.offline_queue.length, 2);
|
||||
});
|
||||
|
||||
@@ -706,10 +726,6 @@ describe("The node_redis client", function () {
|
||||
helper.killConnection(client);
|
||||
});
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
assert.equal(client.command_queue.length, 15);
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
if (/uncertain state/.test(err.message)) {
|
||||
assert.equal(client.command_queue.length, 0);
|
||||
@@ -787,10 +803,6 @@ describe("The node_redis client", function () {
|
||||
helper.killConnection(client);
|
||||
});
|
||||
|
||||
client.on("reconnecting", function (params) {
|
||||
assert.equal(client.command_queue.length, 15);
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
if (err.code === 'UNCERTAIN_STATE') {
|
||||
assert.equal(client.command_queue.length, 0);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
var assert = require('assert');
|
||||
var Queue = require('double-ended-queue');
|
||||
var utils = require('../lib/utils');
|
||||
var intercept = require('intercept-stdout');
|
||||
|
||||
describe('utils.js', function () {
|
||||
|
||||
@@ -40,6 +41,30 @@ describe('utils.js', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('print helper', function () {
|
||||
it('callback with reply', function () {
|
||||
var text = '';
|
||||
var unhookIntercept = intercept(function(data) {
|
||||
text += data;
|
||||
return '';
|
||||
});
|
||||
utils.print(null, 'abc');
|
||||
unhookIntercept();
|
||||
assert.strictEqual(text, 'Reply: abc\n');
|
||||
});
|
||||
|
||||
it('callback with error', function () {
|
||||
var text = '';
|
||||
var unhookIntercept = intercept(function(data) {
|
||||
text += data;
|
||||
return '';
|
||||
});
|
||||
utils.print(new Error('Wonderful exception'));
|
||||
unhookIntercept();
|
||||
assert.strictEqual(text, 'Error: Wonderful exception\n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('reply_in_order', function () {
|
||||
|
||||
var err_count = 0;
|
||||
|
Reference in New Issue
Block a user