You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Improve tests a bit
Reduce timeouts if possible Extend timeouts if needed (windows tests need their time) Don't expose the redis socket to others than the owner Don't create the stunnel log
This commit is contained in:
@@ -23,7 +23,7 @@ describe("The 'expire' method", function () {
|
||||
client.EXPIRE('expiry key', '1', helper.isNumber(1));
|
||||
setTimeout(function () {
|
||||
client.exists(['expiry key'], helper.isNumber(0, done));
|
||||
}, 1100);
|
||||
}, 1050);
|
||||
});
|
||||
|
||||
it('expires key after timeout with array syntax', function (done) {
|
||||
@@ -31,7 +31,7 @@ describe("The 'expire' method", function () {
|
||||
client.EXPIRE(['expiry key', '1'], helper.isNumber(1));
|
||||
setTimeout(function () {
|
||||
client.exists(['expiry key'], helper.isNumber(0, done));
|
||||
}, 1100);
|
||||
}, 1050);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
@@ -90,7 +90,7 @@ describe("The 'flushdb' method", function () {
|
||||
it('results in a db size of zero without a callback', function (done) {
|
||||
client.flushdb();
|
||||
setTimeout(function (err, res) {
|
||||
client.dbsize([], function (err, res) {
|
||||
client.dbsize(function (err, res) {
|
||||
helper.isNotError()(err, res);
|
||||
helper.isType.number()(err, res);
|
||||
assert.strictEqual(0, res, 'Flushing db should result in db size 0');
|
||||
|
@@ -77,7 +77,7 @@ describe("The 'get' method", function () {
|
||||
client.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
setTimeout(done, 50);
|
||||
setTimeout(done, 25);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -34,7 +34,7 @@ describe("The 'info' method", function () {
|
||||
setTimeout(function () {
|
||||
assert.strictEqual(typeof client.server_info.db2, 'object');
|
||||
done();
|
||||
}, 150);
|
||||
}, 30);
|
||||
});
|
||||
|
||||
it('works with optional section provided with and without callback', function (done) {
|
||||
|
@@ -62,7 +62,7 @@ describe("The 'select' method", function () {
|
||||
client.select(1, function (err) {
|
||||
assert.equal(err, null);
|
||||
assert.equal(client.selected_db, 1, 'we should have selected the new valid DB');
|
||||
return done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -73,7 +73,7 @@ describe("The 'select' method", function () {
|
||||
client.select(9999, function (err) {
|
||||
assert.equal(err.code, 'ERR');
|
||||
assert.equal(err.message, 'ERR invalid DB index');
|
||||
return done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -86,8 +86,8 @@ describe("The 'select' method", function () {
|
||||
client.select(1);
|
||||
setTimeout(function () {
|
||||
assert.equal(client.selected_db, 1, 'we should have selected the new valid DB');
|
||||
return done();
|
||||
}, 100);
|
||||
done();
|
||||
}, 25);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -43,7 +43,7 @@ describe("The 'set' method", function () {
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(null, args);
|
||||
client.once('ready', function () {
|
||||
done();
|
||||
client.flushdb(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,6 +62,35 @@ describe("The 'set' method", function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('set expire date in seconds', function (done) {
|
||||
client.set('foo', 'bar', 'ex', 10, helper.isString('OK'));
|
||||
client.pttl('foo', function (err, res) {
|
||||
assert(res >= 10000 - 50); // Max 50 ms should have passed
|
||||
assert(res <= 10000); // Max possible should be 10.000
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('set expire date in milliseconds', function (done) {
|
||||
client.set('foo', 'bar', 'px', 100, helper.isString('OK'));
|
||||
client.pttl('foo', function (err, res) {
|
||||
assert(res >= 50); // Max 50 ms should have passed
|
||||
assert(res <= 100); // Max possible should be 100
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
it('only set the key if (not) already set', function (done) {
|
||||
client.set('foo', 'bar', 'NX', helper.isString('OK'));
|
||||
client.set('foo', 'bar', 'nx', helper.isNull());
|
||||
client.set('foo', 'bar', 'EX', '10', 'XX', helper.isString('OK'));
|
||||
client.ttl('foo', function (err, res) {
|
||||
assert(res >= 9); // Min 9s should be left
|
||||
assert(res <= 10); // Max 10s should be left
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('reports an error with invalid parameters', function () {
|
||||
|
@@ -22,12 +22,11 @@ describe("The 'ttl' method", function () {
|
||||
it('returns the current ttl on a key', function (done) {
|
||||
client.set(['ttl key', 'ttl val'], helper.isString('OK'));
|
||||
client.expire(['ttl key', '100'], helper.isNumber(1));
|
||||
setTimeout(function () {
|
||||
client.TTL(['ttl key'], function (err, ttl) {
|
||||
assert.ok(ttl > 50 && ttl <= 100);
|
||||
return done(err);
|
||||
});
|
||||
}, 200);
|
||||
client.TTL(['ttl key'], function (err, ttl) {
|
||||
assert(ttl >= 99);
|
||||
assert(ttl <= 100);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
|
Reference in New Issue
Block a user