1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Client to emit errors now instead of throwing them asynchronously where they're uncatchable.

This commit is contained in:
Bryce Baril
2013-12-21 11:08:00 -08:00
parent 34a2375bec
commit 6a3ccf64f4
2 changed files with 74 additions and 20 deletions

66
test.js
View File

@@ -402,6 +402,72 @@ tests.FWD_ERRORS_1 = function () {
}, 150);
};
tests.FWD_ERRORS_2 = function () {
var name = "FWD_ERRORS_2";
var toThrow = new Error("Forced exception");
var recordedError = null;
var originalHandler = client.listeners("error").pop();
client.removeAllListeners("error");
client.once("error", function (err) {
recordedError = err;
});
client.get("no_such_key", function (err, reply) {
throw toThrow;
});
setTimeout(function () {
client.listeners("error").push(originalHandler);
assert.equal(recordedError, toThrow, "Should have caught our forced exception");
next(name);
}, 150);
};
tests.FWD_ERRORS_3 = function () {
var name = "FWD_ERRORS_3";
var recordedError = null;
var originalHandler = client.listeners("error").pop();
client.removeAllListeners("error");
client.once("error", function (err) {
recordedError = err;
});
client.send_command("no_such_command", []);
setTimeout(function () {
client.listeners("error").push(originalHandler);
assert.ok(recordedError instanceof Error);
next(name);
}, 150);
};
tests.FWD_ERRORS_4 = function () {
var name = "FWD_ERRORS_4";
var toThrow = new Error("Forced exception");
var recordedError = null;
var originalHandler = client.listeners("error").pop();
client.removeAllListeners("error");
client.once("error", function (err) {
recordedError = err;
});
client.send_command("no_such_command", [], function () {
throw toThrow;
});
setTimeout(function () {
client.listeners("error").push(originalHandler);
assert.equal(recordedError, toThrow, "Should have caught our forced exception");
next(name);
}, 150);
};
tests.EVAL_1 = function () {
var name = "EVAL_1";