Browse files

add setup function for tests and use new process_metrics signature.

  • Loading branch information...
1 parent 1cacf7b commit 39df6b489077abfc99b22a623013fb597608344e @draco2003 committed Oct 15, 2012
Showing with 50 additions and 46 deletions.
  1. +1 −1 lib/process_metrics.js
  2. +49 −45 test/process_metrics_tests.js
View
2 lib/process_metrics.js
@@ -81,7 +81,7 @@ var process_metrics = function (metrics, flushInterval, ts, flushCallback) {
//add processed metrics to the metrics_hash
metrics.counter_rates = counter_rates;
metrics.timer_data = timer_data;
- flushCallback(ts, metrics);
+ flushCallback();
}
exports.process_metrics = process_metrics
View
94 test/process_metrics_tests.js
@@ -1,47 +1,51 @@
var pm = require('../lib/process_metrics')
-var time_stamp = Math.round(new Date().getTime() / 1000);
-var counters = {};
-var gauges = {};
-var timers = {};
-var sets = {};
-var pctThreshold = null;
+module.exports = {
+ setUp: function (callback) {
+ this.time_stamp = Math.round(new Date().getTime() / 1000);
-var metrics = {
- counters: counters,
- gauges: gauges,
- timers: timers,
- sets: sets,
- pctThreshold: pctThreshold
-}
+ var counters = {};
+ var gauges = {};
+ var timers = {};
+ var sets = {};
+ var pctThreshold = null;
-module.exports = {
+ this.metrics = {
+ counters: counters,
+ gauges: gauges,
+ timers: timers,
+ sets: sets,
+ pctThreshold: pctThreshold
+ }
+ callback();
+ },
counters_has_stats_count: function(test) {
test.expect(1);
- metrics.counters['a'] = 2;
- var processed_metrics = new pm.process_metrics(metrics, 1000);
- test.equal(2, processed_metrics.counters['a']);
+ this.metrics.counters['a'] = 2;
+ pm.process_metrics(this.metrics, 1000, this.time_stamp, function(){});
+ test.equal(2, this.metrics.counters['a']);
test.done();
},
counters_has_correct_rate: function(test) {
test.expect(1);
- metrics.counters['a'] = 2;
- var processed_metrics = new pm.process_metrics(metrics, 100);
- test.equal(20, processed_metrics.counter_rates['a']);
+ this.metrics.counters['a'] = 2;
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ test.equal(20, this.metrics.counter_rates['a']);
test.done();
},
timers_handle_empty: function(test) {
test.expect(1);
- metrics.timers['a'] = [];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- test.equal(20, processed_metrics.counter_rates['a']);
+ this.metrics.timers['a'] = [];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ //potentially a cleaner way to check this
+ test.equal(undefined, this.metrics.counter_rates['a']);
test.done();
},
timers_single_time: function(test) {
test.expect(6);
- metrics.timers['a'] = [100];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- timer_data = processed_metrics.timer_data['a'];
+ this.metrics.timers['a'] = [100];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ timer_data = this.metrics.timer_data['a'];
test.equal(0, timer_data.std);
test.equal(100, timer_data.upper);
test.equal(100, timer_data.lower);
@@ -52,9 +56,9 @@ module.exports = {
},
timers_multiple_times: function(test) {
test.expect(6);
- metrics.timers['a'] = [100, 200, 300];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- timer_data = processed_metrics.timer_data['a'];
+ this.metrics.timers['a'] = [100, 200, 300];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ timer_data = this.metrics.timer_data['a'];
test.equal(81.64965809277261, timer_data.std);
test.equal(300, timer_data.upper);
test.equal(100, timer_data.lower);
@@ -65,21 +69,21 @@ module.exports = {
},
timers_single_time_single_percentile: function(test) {
test.expect(3);
- metrics.timers['a'] = [100];
- metrics.pctThreshold = [90];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- timer_data = processed_metrics.timer_data['a'];
+ this.metrics.timers['a'] = [100];
+ this.metrics.pctThreshold = [90];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ timer_data = this.metrics.timer_data['a'];
test.equal(100, timer_data.mean_90);
test.equal(100, timer_data.upper_90);
test.equal(100, timer_data.sum_90);
test.done();
},
timers_single_time_multiple_percentiles: function(test) {
test.expect(6);
- metrics.timers['a'] = [100];
- metrics.pctThreshold = [90, 80];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- timer_data = processed_metrics.timer_data['a'];
+ this.metrics.timers['a'] = [100];
+ this.metrics.pctThreshold = [90, 80];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ timer_data = this.metrics.timer_data['a'];
test.equal(100, timer_data.mean_90);
test.equal(100, timer_data.upper_90);
test.equal(100, timer_data.sum_90);
@@ -90,21 +94,21 @@ module.exports = {
},
timers_multiple_times_single_percentiles: function(test) {
test.expect(3);
- metrics.timers['a'] = [100, 200, 300];
- metrics.pctThreshold = [90];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- timer_data = processed_metrics.timer_data['a'];
+ this.metrics.timers['a'] = [100, 200, 300];
+ this.metrics.pctThreshold = [90];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ timer_data = this.metrics.timer_data['a'];
test.equal(200, timer_data.mean_90);
test.equal(300, timer_data.upper_90);
test.equal(600, timer_data.sum_90);
test.done();
},
timers_multiple_times_multiple_percentiles: function(test) {
test.expect(6);
- metrics.timers['a'] = [100, 200, 300];
- metrics.pctThreshold = [90, 80];
- var processed_metrics = new pm.process_metrics(metrics, 100);
- timer_data = processed_metrics.timer_data['a'];
+ this.metrics.timers['a'] = [100, 200, 300];
+ this.metrics.pctThreshold = [90, 80];
+ pm.process_metrics(this.metrics, 100, this.time_stamp, function(){});
+ timer_data = this.metrics.timer_data['a'];
test.equal(200, timer_data.mean_90);
test.equal(300, timer_data.upper_90);
test.equal(600, timer_data.sum_90);

0 comments on commit 39df6b4

Please sign in to comment.