From bac8a57663e6525a6bdfbff31b34f0b37548cd18 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 1 Nov 2012 19:12:39 +0000 Subject: [PATCH] semi-reliable test case for dtrace support --- Makefile | 35 ++++++++++++++++++++--------------- lib/bunyan.js | 2 +- package.json | 2 +- test/dtrace.test.js | 26 ++++++++++++++++---------- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 6a9c4c3..08acfb8 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/lib/bunyan.js b/lib/bunyan.js index ec549d7..6d48426 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -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; } diff --git a/package.json b/package.json index a127273..47dfce6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/dtrace.test.js b/test/dtrace.test.js index 193baf2..c6ed039 100644 --- a/test/dtrace.test.js +++ b/test/dtrace.test.js @@ -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? });