You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add good stack traces tests and fix stack traces in debug mode
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var debug_mode = require('../').debug_mode;
|
var betterStackTraces = /development/i.test(process.env.NODE_ENV) || /\bredis\b/i.test(process.env.NODE_DEBUG);
|
||||||
var betterStackTraces = process.env.NODE_ENV && process.env.NODE_ENV.toUpperCase() === 'DEVELOPMENT' || debug_mode;
|
|
||||||
|
|
||||||
function Command (command, args, callback, call_on_write) {
|
function Command (command, args, callback, call_on_write) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
59
test/good_traces.spec.js
Normal file
59
test/good_traces.spec.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
var config = require('./lib/config');
|
||||||
|
var fork = require('child_process').fork;
|
||||||
|
var redis = config.redis;
|
||||||
|
|
||||||
|
describe('stack traces', function () {
|
||||||
|
|
||||||
|
it('should return good traces with NODE_ENV=development set', function (done) {
|
||||||
|
var external = fork('./test/lib/good-traces.js', {
|
||||||
|
env: {
|
||||||
|
NODE_ENV: 'development'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var id = setTimeout(function () {
|
||||||
|
external.kill();
|
||||||
|
done(new Error('Timeout'));
|
||||||
|
}, 6000);
|
||||||
|
|
||||||
|
external.on('close', function (code) {
|
||||||
|
clearTimeout(id);
|
||||||
|
assert.strictEqual(code, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return good traces with NODE_DEBUG=redis env set', function (done) {
|
||||||
|
var external = fork('./test/lib/good-traces.js', {
|
||||||
|
env: {
|
||||||
|
NODE_DEBUG: 'redis'
|
||||||
|
},
|
||||||
|
silent: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var id = setTimeout(function () {
|
||||||
|
external.kill();
|
||||||
|
done(new Error('Timeout'));
|
||||||
|
}, 6000);
|
||||||
|
|
||||||
|
external.on('close', function (code) {
|
||||||
|
clearTimeout(id);
|
||||||
|
assert.strictEqual(code, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// This is always going to return good stack traces
|
||||||
|
it('should always return good stack traces for rejected offline commands', function (done) {
|
||||||
|
var client = redis.createClient({
|
||||||
|
enable_offline_queue: false
|
||||||
|
});
|
||||||
|
client.set('foo', function (err, res) {
|
||||||
|
assert(/good_traces.spec.js/.test(err.stack));
|
||||||
|
client.quit(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
20
test/lib/good-traces.js
Normal file
20
test/lib/good-traces.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Spawned by the good_stacks.spec.js tests
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
var redis = require('../../index');
|
||||||
|
var client = redis.createClient();
|
||||||
|
|
||||||
|
// Both error cases would normally return bad stack traces
|
||||||
|
client.set('foo', function (err, res) {
|
||||||
|
assert(/good-traces.js:9:8/.test(err.stack));
|
||||||
|
client.set('foo', 'bar', function (err, res) {
|
||||||
|
assert(/good-traces.js:11:12/.test(err.stack));
|
||||||
|
client.quit(function () {
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
process.nextTick(function () {
|
||||||
|
client.stream.destroy();
|
||||||
|
});
|
||||||
|
});
|
@@ -851,7 +851,7 @@ describe('The node_redis client', function () {
|
|||||||
|
|
||||||
var id = setTimeout(function () {
|
var id = setTimeout(function () {
|
||||||
external.kill();
|
external.kill();
|
||||||
done(Error('unref subprocess timed out'));
|
done(new Error('unref subprocess timed out'));
|
||||||
}, 8000);
|
}, 8000);
|
||||||
|
|
||||||
external.on('close', function (code) {
|
external.on('close', function (code) {
|
||||||
|
Reference in New Issue
Block a user