Permalink
Browse files

Add event to stop intervals. Tests now stop properly

  • Loading branch information...
1 parent 84cf06d commit b19594e01bb4daea0bd6ff0d433fcf60d41be730 marogers committed Mar 29, 2012
Showing with 11 additions and 1 deletion.
  1. +6 −0 stats/exponentially_weighted_moving_average.js
  2. +5 −1 tests/test_all.js
@@ -19,6 +19,8 @@ var ExponentiallyWeightedMovingAverage = EWMA = module.exports = function Expone
if (interval) {
this.tickInterval = setInterval(function(){ self.tick(); }, interval);
}
+ // need to stop things that hold the event loop open
+ process.on('_metrics:stop_all', this.stop.bind(this));
}
ExponentiallyWeightedMovingAverage.prototype.update = function(n) {
@@ -47,6 +49,10 @@ ExponentiallyWeightedMovingAverage.prototype.rate = function() {
return this.currentRate * 1000;
}
+ExponentiallyWeightedMovingAverage.prototype.stop = function() {
+ clearInterval(this.tickInterval);
+}
+
module.exports.createM1EWMA = function(){ return new EWMA(M1_ALPHA, 5000); }
module.exports.createM5EWMA = function(){ return new EWMA(M5_ALPHA, 5000); }
module.exports.createM15EWMA = function(){ return new EWMA(M15_ALPHA, 5000); }
View
@@ -15,7 +15,11 @@ var compose = function() {
};
compose(
- require('./test_exponentially_weighted_moving_average')
+ function() {
+ // stop any node event loop timers
+ process.emit('_metrics:stop_all');
+ }
+, require('./test_exponentially_weighted_moving_average')
, require('./test_exponentially_decaying_sample')
, require('./test_uniform_sample')
, require('./meter')

0 comments on commit b19594e

Please sign in to comment.