Skip to content

Commit 228742b

Browse files
committed
Do not export lrtime if it is not implemented
If lrtime is not implemented (and it is currently only implemented on Linux), then do not export it as a function, allowing users of appmetrics to implement a simple feature test to see if it is available.
1 parent e486496 commit 228742b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@ module.exports.monitor = function() {
241241
return this.api;
242242
};
243243

244-
module.exports.lrtime = function() {
245-
return agent.lrtime();
246-
};
244+
module.exports.lrtime = agent.lrtime;
247245

248246
module.exports.configure = function(options) {
249247
options = options || {};
@@ -262,4 +260,4 @@ module.exports.setJSONProfilingMode = function(val) {
262260

263261
module.exports.getJSONProfilingMode = function() {
264262
return jsonProfilingMode;
265-
}
263+
}

tests/api_tests.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@ var monitor = app.appmetrics.monitor();
1919
app.appmetrics.enable("profiling");
2020

2121
var tap = require('tap');
22-
tap.plan(5); // NOTE: This needs to be updated when tests are added/removed
22+
tap.plan(6); // NOTE: This needs to be updated when tests are added/removed
2323
tap.tearDown(function(){
2424
app.endRun();
2525
});
2626

27+
tap.test('lrtime is a function or undefined', function(t) {
28+
var lrtime = app.appmetrics.lrtime;
29+
30+
if (lrtime) {
31+
t.doesNotThrow(lrtime, 'callable, not just present');
32+
} else {
33+
t.notEqual(process.platform, 'linux', 'lrtime mandatory on linux');
34+
}
35+
t.end();
36+
});
37+
2738
var completedTests = {}; //Stores which tests have been run, ensures single run per test
2839

2940
monitor.on('cpu', function(data) {
@@ -394,4 +405,4 @@ function runEventLoopTests(elData, t){
394405
t.ok(elData.latency[elem] <= 5000,
395406
"Contains " + elem + " latency value less that 5 seconds");
396407
}
397-
}
408+
}

0 commit comments

Comments
 (0)