You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
@@ -1,9 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var config = require("./lib/config");
|
||||
var utils = require("../lib/utils");
|
||||
var redis = config.redis;
|
||||
var parsers = [
|
||||
require("../lib/parsers/javascript").Parser
|
||||
];
|
||||
@@ -73,37 +71,108 @@ describe('parsers', function () {
|
||||
assert.equal(reply_count, 3, "check reply should have been called three times");
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Activate this if you want to fry your cpu / memory
|
||||
describe.skip("test out of memory", function () {
|
||||
var args = config.configureClient('javascript', '127.0.0.1');
|
||||
var clients = new Array(300).join(" ").split(" ");
|
||||
var client;
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.once("connect", function () {
|
||||
client.flushdb(done);
|
||||
it('multiple chunks in a bulk string', function (done) {
|
||||
var parser = new Parser();
|
||||
var reply_count = 0;
|
||||
function check_reply(reply) {
|
||||
reply = utils.reply_to_strings(reply);
|
||||
assert.strictEqual(reply, "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij");
|
||||
reply_count++;
|
||||
}
|
||||
parser.send_reply = check_reply;
|
||||
|
||||
parser.execute(new Buffer('$100\r\nabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
assert.strictEqual(reply_count, 0);
|
||||
parser.execute(new Buffer('\r\n'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
|
||||
parser.execute(new Buffer('$100\r'));
|
||||
parser.execute(new Buffer('\nabcdefghijabcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghij'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
parser.execute(new Buffer(
|
||||
'abcdefghij\r\n' +
|
||||
'$100\r\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij\r\n' +
|
||||
'$100\r\nabcdefghijabcdefghijabcdefghijabcdefghij'
|
||||
));
|
||||
assert.strictEqual(reply_count, 3);
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij\r'));
|
||||
assert.strictEqual(reply_count, 3);
|
||||
parser.execute(new Buffer('\n'));
|
||||
|
||||
assert.equal(reply_count, 4, "check reply should have been called three times");
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reach limit and wait for further data', function (done) {
|
||||
setTimeout(done, 5000);
|
||||
clients.forEach(function(entry, a) {
|
||||
var max = 0;
|
||||
var client = redis.createClient.apply(redis.createClient, args);
|
||||
client.on('ready', function() {
|
||||
while (++max < 50) {
|
||||
var item = [];
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
item.push('aaa' + (Math.random() * 1000000 | 0));
|
||||
}
|
||||
client.del('foo' + a);
|
||||
client.lpush('foo' + a, item);
|
||||
client.lrange('foo' + a, 0, 99);
|
||||
}
|
||||
});
|
||||
it('multiple chunks with arrays different types', function (done) {
|
||||
var parser = new Parser();
|
||||
var reply_count = 0;
|
||||
function check_reply(reply) {
|
||||
reply = utils.reply_to_strings(reply);
|
||||
assert.deepStrictEqual(reply, [
|
||||
'abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij',
|
||||
'test',
|
||||
100,
|
||||
new Error('Error message'),
|
||||
['The force awakens']
|
||||
]);
|
||||
reply_count++;
|
||||
}
|
||||
parser.send_reply = check_reply;
|
||||
|
||||
parser.execute(new Buffer('*5\r\n$100\r\nabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij'));
|
||||
parser.execute(new Buffer('abcdefghijabcdefghijabcdefghij\r\n'));
|
||||
parser.execute(new Buffer('+test\r'));
|
||||
parser.execute(new Buffer('\n:100'));
|
||||
parser.execute(new Buffer('\r\n-Error message'));
|
||||
parser.execute(new Buffer('\r\n*1\r\n$17\r\nThe force'));
|
||||
assert.strictEqual(reply_count, 0);
|
||||
parser.execute(new Buffer(' awakens\r\n$5'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
return done();
|
||||
});
|
||||
|
||||
it('return normal errors', function (done) {
|
||||
var parser = new Parser();
|
||||
var reply_count = 0;
|
||||
function check_reply(reply) {
|
||||
assert.equal(reply.message, 'Error message');
|
||||
reply_count++;
|
||||
}
|
||||
parser.send_error = check_reply;
|
||||
|
||||
parser.execute(new Buffer('-Error '));
|
||||
parser.execute(new Buffer('message\r\n*3\r\n$17\r\nThe force'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
parser.execute(new Buffer(' awakens\r\n$5'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
return done();
|
||||
});
|
||||
|
||||
it('return null for empty arrays and empty bulk strings', function (done) {
|
||||
var parser = new Parser();
|
||||
var reply_count = 0;
|
||||
function check_reply(reply) {
|
||||
assert.equal(reply, null);
|
||||
reply_count++;
|
||||
}
|
||||
parser.send_reply = check_reply;
|
||||
|
||||
parser.execute(new Buffer('$-1\r\n*-'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
parser.execute(new Buffer('1'));
|
||||
assert.strictEqual(reply_count, 1);
|
||||
parser.execute(new Buffer('\r\n$-'));
|
||||
assert.strictEqual(reply_count, 2);
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user