Commit bb2444e4 authored by Alan Szlosek's avatar Alan Szlosek

prevent dangling redisClient connection in tests

parent 45d47c7f
Pipeline #11194156 failed with stage
in 43 seconds
......@@ -4,13 +4,14 @@ var moment = require('moment');
var Harbinger = require('../index');
/*
var redisClient = redis.createClient(6379, 'redis');
redisClient.on("error", function (err) {
console.log("Error " + err);
});
redisClient.on("end", function(err) {
//console.log("Redis connection closed");
});
*/
var series = function(func, thisarg, args, callback) {
......@@ -48,9 +49,15 @@ var series = function(func, thisarg, args, callback) {
};
var done = function(test, redisClient) {
test.done();
redisClient.quit();
};
tap.test('timeseries.count.single', function(test) {
var self = this;
var redisClient = redis.createClient(6379, 'redis');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing');
var secondsBucket = moment().unix() - 100;
......@@ -58,19 +65,19 @@ tap.test('timeseries.count.single', function(test) {
ts.count(secondsBucket, 3, function(err) {
if (err) {
test.done();
done(test, redisClient);
return;
}
ts.getCounts(secondsBucket, secondsBucket, function(err, result) {
if (err) {
console.log(err);
test.done();
done(test, redisClient);
return;
}
test.equals(1, result.length);
test.equals(3, result[0]);
test.done();
done(test, redisClient);
});
});
});
......@@ -82,6 +89,7 @@ To calculate the error rate, we have to read from multiple keys. Can use Redis m
*/
tap.test('timeseries.getCounts', function(test) {
var self = this;
var redisClient = redis.createClient(6379, 'redis');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing2');
var secondsBucket = moment().unix() - 200;
......@@ -97,7 +105,7 @@ tap.test('timeseries.getCounts', function(test) {
function(err, out) {
if (err) {
console.log('Err', err);
test.done();
done(test, redisClient);
return;
}
test.ok(true);
......@@ -108,11 +116,11 @@ tap.test('timeseries.getCounts', function(test) {
function(err, out) {
if (err) {
console.log('Err2', err);
test.done();
done(test, redisClient);
return;
}
test.equals( out.join(','), '3,0,4');
test.done();
done(test, redisClient);
}
);
......@@ -123,6 +131,7 @@ tap.test('timeseries.getCounts', function(test) {
tap.test('timeseries.getCountStatistics', function(test) {
var self = this;
var redisClient = redis.createClient(6379, 'redis');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing2');
var secondsBucket = moment().unix() - 300;
......@@ -137,7 +146,7 @@ tap.test('timeseries.getCountStatistics', function(test) {
],
function(err, out) {
if (err) {
test.done();
done(test, redisClient);
return;
}
test.ok(true);
......@@ -147,13 +156,13 @@ tap.test('timeseries.getCountStatistics', function(test) {
secondsBucket + 2,
function(err, stats) {
if (err) {
test.done();
done(test, redisClient);
return;
}
test.equals(3, stats.mean);
test.equals(3, stats.count);
test.equals(9, stats.sum);
test.done();
done(test, redisClient);
}
);
......@@ -164,6 +173,7 @@ tap.test('timeseries.getCountStatistics', function(test) {
tap.test('timeseries.getTimes', function(test) {
var self = this;
var redisClient = redis.createClient(6379, 'redis');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing-times');
var secondsBucket = moment().unix() - 200;
......@@ -179,7 +189,7 @@ tap.test('timeseries.getTimes', function(test) {
function(err, out) {
if (err) {
console.log('Err', err);
test.end();
done(test, redisClient);
return;
}
test.ok(true);
......@@ -190,11 +200,11 @@ tap.test('timeseries.getTimes', function(test) {
function(err, out) {
if (err) {
console.log('Err2', err);
test.end();
done(test, redisClient);
return;
}
test.equals( out.join(','), '200,900');
test.end();
done(test, redisClient);
}
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment