more reliable dtrace test, drop node0.9 testing (dtrace-provider doesn't work)

This commit is contained in:
Trent Mick 2012-11-01 20:05:56 +00:00
parent bac8a57663
commit b260bdb934
3 changed files with 32 additions and 34 deletions

View file

@ -77,7 +77,7 @@ test: $(TAP)
# Note: 'test08' is last so (if all is well) I end up with a binary # Note: 'test08' is last so (if all is well) I end up with a binary
# dtrace-provider build for node 0.8 (my current version). # dtrace-provider build for node 0.8 (my current version).
.PHONY: testall .PHONY: testall
testall: test06 test09 test08 testall: test06 test08
.PHONY: test09 .PHONY: test09
test09: test09:

View file

@ -35,51 +35,36 @@ if (!runDtraceTests) {
if (runDtraceTests) { if (runDtraceTests) {
test('basic', function (t) { test('basic dtrace', function (t) {
var log = bunyan.createLogger({name: 'basic'}); // at default 'info' level var argv = ['dtrace', '-Z', '-x', 'strsize=4k', '-qn',
'bunyan$target:::log-*{printf("%s", copyinstr(arg0))}',
// Should be '%%s' in that `format` frankly, but node *0.6* doesn't see '-c', format('node %s/log-some.js', __dirname)];
// it that way. Node *0.8* has fixed '%%' handling.
var argv = ['dtrace', '-x', 'strsize=4k', '-qn',
format('bunyan%d:::log-*{printf("%s", copyinstr(arg0))}', process.pid)];
var dtrace = spawn(argv[0], argv.slice(1)); var dtrace = spawn(argv[0], argv.slice(1));
//console.error("ARGV: %j", argv); //console.error("ARGV: %j", argv);
var traces = []; var traces = [];
dtrace.stdout.on('data', function (data) { dtrace.stdout.on('data', function (data) {
//console.error("STDOUT:", data.toString()); //console.error("DTRACE STDOUT:", data.toString());
traces.push(data.toString()); traces.push(data.toString());
}); });
dtrace.stderr.on('data', function (data) { dtrace.stderr.on('data', function (data) {
console.error(data.toString()); console.error("DTRACE STDERR:", data.toString());
}); });
dtrace.on('exit', function (code) { dtrace.on('exit', function (code) {
if (code) { t.notOk(code, 'dtrace exited cleanly');
console.log("# error: dtrace exited non-zero:", code);
}
});
setTimeout(function () {
log.debug({basic: true}, 'hi at debug');
log.trace({basic: true}, 'hi at trace');
setTimeout(function () {
dtrace.kill('SIGTERM');
traces = traces.join('').split('\n') traces = traces.join('').split('\n')
.filter(function (t) { return t.trim().length }) .filter(function (t) { return t.trim().length })
.map(function (t) { return JSON.parse(t) }); .map(function (t) { return JSON.parse(t) });
t.equal(traces.length, 2, t.equal(traces.length, 2, 'got 2 log records');
"(If this fails, it is often a timing issue. Please try again.)");
if (traces.length) { if (traces.length) {
t.equal(traces[0].pid, process.pid);
t.equal(traces[0].level, bunyan.DEBUG); t.equal(traces[0].level, bunyan.DEBUG);
t.equal(traces[1].basic, true); t.equal(traces[0].foo, 'bar');
t.equal(traces[1].level, bunyan.TRACE);
t.equal(traces[1].msg, 'hi at trace');
} }
t.end(); t.end();
}, 1000); });
}, 3000); // Give dtrace some time to startup. How much?
}); });
} /* end of `if (runDtraceTests)` */ } /* end of `if (runDtraceTests)` */

13
test/log-some.js Normal file
View file

@ -0,0 +1,13 @@
// A helper script to log a few times. We attempt to NOT emit
// to stdout or stderr because this is used for dtrace testing
// and we don't want to mix output.
var bunyan = require('../lib/bunyan');
var log = bunyan.createLogger({
name: 'play',
serializers: bunyan.stdSerializers
});
log.debug({foo: 'bar'}, 'hi at debug')
log.trace('hi at trace')