You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Fix test race condition
This commit is contained in:
@@ -133,6 +133,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) {
|
it("emit an error after the socket timeout exceeded the connect_timeout time", function (done) {
|
||||||
var connect_timeout = 1000; // in ms
|
var connect_timeout = 1000; // in ms
|
||||||
|
var time = Date.now();
|
||||||
client = redis.createClient({
|
client = redis.createClient({
|
||||||
parser: parser,
|
parser: parser,
|
||||||
host: '192.168.74.167', // Should be auto detected as ipv4
|
host: '192.168.74.167', // Should be auto detected as ipv4
|
||||||
@@ -143,7 +144,6 @@ describe("connection tests", function () {
|
|||||||
});
|
});
|
||||||
assert.strictEqual(client.address, '192.168.74.167:6379');
|
assert.strictEqual(client.address, '192.168.74.167:6379');
|
||||||
assert.strictEqual(client.connection_options.family, 4);
|
assert.strictEqual(client.connection_options.family, 4);
|
||||||
var time = Date.now();
|
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on("reconnecting", function (params) {
|
||||||
throw new Error('No reconnect, since no connection was ever established');
|
throw new Error('No reconnect, since no connection was ever established');
|
||||||
@@ -152,7 +152,7 @@ describe("connection tests", function () {
|
|||||||
client.on('error', function(err) {
|
client.on('error', function(err) {
|
||||||
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message));
|
assert(/Redis connection in broken state: connection timeout.*?exceeded./.test(err.message));
|
||||||
assert(Date.now() - time < connect_timeout + 50);
|
assert(Date.now() - time < connect_timeout + 50);
|
||||||
assert(Date.now() - time >= connect_timeout);
|
assert(Date.now() - time >= connect_timeout - 50); // Somehow this is triggered to early at times
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -192,9 +192,7 @@ describe("connection tests", function () {
|
|||||||
connect_timeout: 1000
|
connect_timeout: 1000
|
||||||
});
|
});
|
||||||
|
|
||||||
client.once('ready', function() {
|
client.once('ready', done);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
@@ -207,10 +205,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
var end = helper.callFuncAfter(done, 2);
|
var end = helper.callFuncAfter(done, 2);
|
||||||
|
|
||||||
client.once('ready', function() {
|
client.once('ready', end);
|
||||||
end();
|
|
||||||
});
|
|
||||||
|
|
||||||
client.set('foo', 'bar', end);
|
client.set('foo', 'bar', end);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -221,9 +216,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
client.once("ready", function () {
|
client.once("ready", function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener("error", done);
|
||||||
client.get("recon 1", function (err, res) {
|
client.get("recon 1", done);
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -233,9 +226,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
client.once("ready", function () {
|
client.once("ready", function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener("error", done);
|
||||||
client.get("recon 1", function (err, res) {
|
client.get("recon 1", done);
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -246,9 +237,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
client.once("ready", function () {
|
client.once("ready", function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener("error", done);
|
||||||
client.get("recon 1", function (err, res) {
|
client.get("recon 1", done);
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,9 +247,7 @@ describe("connection tests", function () {
|
|||||||
|
|
||||||
client.once("ready", function () {
|
client.once("ready", function () {
|
||||||
client.removeListener("error", done);
|
client.removeListener("error", done);
|
||||||
client.get("recon 1", function (err, res) {
|
client.get("recon 1", done);
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -385,9 +372,7 @@ describe("connection tests", function () {
|
|||||||
connect_timeout: 1000
|
connect_timeout: 1000
|
||||||
});
|
});
|
||||||
assert.strictEqual(client.options.connect_timeout, 1000);
|
assert.strictEqual(client.options.connect_timeout, 1000);
|
||||||
client.on('ready', function () {
|
client.on('ready', done);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url in the options object and works with protocols other than the redis protocol (e.g. http)', function (done) {
|
it('allows connecting with the redis url in the options object and works with protocols other than the redis protocol (e.g. http)', function (done) {
|
||||||
@@ -398,9 +383,7 @@ describe("connection tests", function () {
|
|||||||
assert.strictEqual(+client.selected_db, 3);
|
assert.strictEqual(+client.selected_db, 3);
|
||||||
assert(!client.options.port);
|
assert(!client.options.port);
|
||||||
assert.strictEqual(client.options.host, config.HOST[ip]);
|
assert.strictEqual(client.options.host, config.HOST[ip]);
|
||||||
client.on("ready", function () {
|
client.on("ready", done);
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url and no auth and options as second parameter', function (done) {
|
it('allows connecting with the redis url and no auth and options as second parameter', function (done) {
|
||||||
@@ -409,18 +392,14 @@ describe("connection tests", function () {
|
|||||||
};
|
};
|
||||||
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, options);
|
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, options);
|
||||||
assert.strictEqual(Object.keys(options).length, 1);
|
assert.strictEqual(Object.keys(options).length, 1);
|
||||||
client.on("ready", function () {
|
client.on("ready", done);
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows connecting with the redis url and no auth and options as third parameter', function (done) {
|
it('allows connecting with the redis url and no auth and options as third parameter', function (done) {
|
||||||
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, null, {
|
client = redis.createClient('redis://' + config.HOST[ip] + ':' + config.PORT, null, {
|
||||||
detect_buffers: false
|
detect_buffers: false
|
||||||
});
|
});
|
||||||
client.on("ready", function () {
|
client.on("ready", done);
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user