semi-reliable test case for dtrace support

This commit is contained in:
Trent Mick 2012-11-01 19:12:39 +00:00
parent 8732764c67
commit bac8a57663
4 changed files with 38 additions and 27 deletions

View file

@ -2,6 +2,14 @@
#---- Tools
TAP := ./node_modules/.bin/tap
SUDO := sudo
ifeq ($(shell uname -s),SunOS)
# On SunOS (e.g. SmartOS) we expect to run the test suite as the
# root user -- necessary to run dtrace. Therefore `pfexec` isn't
# necessary.
SUDO :=
endif
#---- Files
@ -50,12 +58,19 @@ publish:
&& git commit -a -m "publish latest docs" \
&& git push origin gh-pages || true)
.PHONY: distclean
distclean:
rm -rf node_modules
#---- test
.PHONY: test
test: $(TAP)
TAP=1 $(TAP) $(TEST_FILES)
[[ -n "$(SKIP_DTRACE)" ]] || sudo TAP=1 $(TAP) test/dtrace.test.js
[[ -n "$(SKIP_DTRACE)" ]] || \
node -e 'require("trentm-dtrace-provider").createDTraceProvider("isthisthingon")' && \
$(SUDO) $(TAP) --tap test/dtrace.test.js
$(TAP) --tap $(TEST_FILES)
# Test will all node supported versions (presumes install locations I use on
# my machine).
@ -67,25 +82,15 @@ testall: test06 test09 test08
.PHONY: test09
test09:
@echo "# Test node 0.9.x (with node `$(HOME)/opt/node-0.9/bin/node --version`)"
[[ -n "$(SKIP_DTRACE)" ]] \
|| PATH="$(HOME)/opt/node-0.9/bin:$(PATH)" npm rebuild dtrace-provider \
&& sudo PATH="$(HOME)/opt/node-0.9/bin:$(PATH)" TAP=1 $(TAP) test/dtrace.test.js
PATH="$(HOME)/opt/node-0.9/bin:$(PATH)" TAP=1 $(TAP) $(TEST_FILES)
PATH="$(HOME)/opt/node-0.9/bin:$(PATH)" make distclean all test
.PHONY: test08
test08:
@echo "# Test node 0.8.x (with node `$(HOME)/opt/node-0.8/bin/node --version`)"
[[ -n "$(SKIP_DTRACE)" ]] \
|| PATH="$(HOME)/opt/node-0.8/bin:$(PATH)" npm rebuild dtrace-provider \
&& sudo PATH="$(HOME)/opt/node-0.8/bin:$(PATH)" TAP=1 $(TAP) test/dtrace.test.js
PATH="$(HOME)/opt/node-0.8/bin:$(PATH)" TAP=1 $(TAP) $(TEST_FILES)
PATH="$(HOME)/opt/node-0.8/bin:$(PATH)" make distclean all test
.PHONY: test06
test06:
@echo "# Test node 0.6.x (with node `$(HOME)/opt/node-0.6/bin/node --version`)"
[[ -n "$(SKIP_DTRACE)" ]] \
|| PATH="$(HOME)/opt/node-0.6/bin:$(PATH)" npm rebuild dtrace-provider \
&& sudo PATH="$(HOME)/opt/node-0.6/bin:$(PATH)" TAP=1 $(TAP) test/dtrace.test.js
PATH="$(HOME)/opt/node-0.6/bin:$(PATH)" TAP=1 $(TAP) $(TEST_FILES)
PATH="$(HOME)/opt/node-0.6/bin:$(PATH)" make distclean all test
#---- check

View file

@ -26,7 +26,7 @@ var fs = require('fs');
var util = require('util');
var assert = require('assert');
try {
var dtrace = require('dtrace-provider');
var dtrace = require('trentm-dtrace-provider');
} catch (e) {
dtrace = null;
}

View file

@ -16,7 +16,7 @@
"keywords": ["log", "logging", "log4j", "json"],
"dependencies": {
"dtrace-provider": "0.2.3"
"trentm-dtrace-provider": "0.2.4"
},
"devDependencies": {
"tap": "0.2.0",

View file

@ -15,9 +15,9 @@ var bunyan = require('../lib/bunyan');
var dtracePlats = ['sunos', 'darwin', 'freebsd'];
var runDtraceTests = true;
try {
require('dtrace-provider')
require('trentm-dtrace-provider')
} catch (e) {
console.log('# skip dtrace tests: no dtrace-provider module');
console.log('# skip dtrace tests: no trentm-dtrace-provider module');
runDtraceTests = false;
}
if (!runDtraceTests) {
@ -40,10 +40,13 @@ test('basic', function (t) {
// Should be '%%s' in that `format` frankly, but node *0.6* doesn't see
// it that way. Node *0.8* has fixed '%%' handling.
var dtrace = spawn('dtrace', ['-x', 'strsize=4k', '-qn',
format('bunyan%d:::log-*{printf("%s", copyinstr(arg0))}', process.pid)]);
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));
//console.error("ARGV: %j", argv);
var traces = [];
dtrace.stdout.on('data', function (data) {
//console.error("STDOUT:", data.toString());
traces.push(data.toString());
});
dtrace.stderr.on('data', function (data) {
@ -51,7 +54,7 @@ test('basic', function (t) {
});
dtrace.on('exit', function (code) {
if (code) {
console.log("dtrace exited non-zero:", code);
console.log("# error: dtrace exited non-zero:", code);
}
});
@ -65,13 +68,16 @@ test('basic', function (t) {
traces = traces.join('').split('\n')
.filter(function (t) { return t.trim().length })
.map(function (t) { return JSON.parse(t) });
t.equal(traces.length, 2);
t.equal(traces[0].pid, process.pid);
t.equal(traces[0].level, bunyan.DEBUG);
t.equal(traces[1].basic, true);
t.equal(traces.length, 2,
"(If this fails, it is often a timing issue. Please try again.)");
if (traces.length) {
t.equal(traces[0].pid, process.pid);
t.equal(traces[0].level, bunyan.DEBUG);
t.equal(traces[1].basic, true);
}
t.end();
}, 1000);
}, 1000); // Give dtrace some time to startup. How much?
}, 3000); // Give dtrace some time to startup. How much?
});