Commit 77688f49 authored by Alan Szlosek's avatar Alan Szlosek

migrate more tests to tap

parent 27492cf0
Pipeline #11106547 passed with stage
in 56 seconds
......@@ -13,7 +13,7 @@ tap.test('linebuffer', function(test) {
test.equals(expectedLine, line);
if (lines.length == 0) {
test.done();
test.end();
}
});
test.plan(4);
......
......@@ -17,6 +17,6 @@ tap.test('createMessage', function(test) {
test.equal(message.localAddress, '192.168.1.2')
test.equal(message.localPort, 10000);
// TODO: should also make sure it has receivedMilliseconds
test.done();
test.end();
});
var tap = require('tap');
var server = new harbinger.Input.StatsD();
tap.test('statsd', function(test) {
setUp: function(callback) {
callback();
},
tearDown: function(callback) {
this.server.close();
callback();
},
var Harbinger = require('../index');
var server = new Harbinger.Input.StatsD();
var udp = require('dgram').createSocket('udp4');
udp.unref();
basic: function(test) {
tap.test('statsd.basic', function(test) {
var message = "application.module.request.count:1|c\n";
var out = {
metric: 'application.module.request.count',
......@@ -26,14 +21,14 @@ tap.test('statsd', function(test) {
test.equal(type, out.type);
test.equal(sampleRate, out.sampleRate);
test.equal(remoteAddress, out.remoteAddress);
test.end();
test.done();
server.close();
};
test.expect(5);
this.server.callback(cb);
this.server.bind(8125, '127.0.0.1');
test.plan(5);
server.callback(cb);
server.bind(8125, '127.0.0.1');
udp.send(message, 0, message.length, 8125, '127.0.0.1');
}
});
var tap = require('tap');
var moment = require('moment');
var harbinger = require('../index');
tap.test('syslog.singleLines', function(test) {
var dt = new Date();
......@@ -17,7 +20,7 @@ tap.test('syslog.singleLines', function(test) {
msg: '(alan) CMD (php /home/alan/coding/projects/profiling/scripts/process.php)'
}
];
test.expect(1);
test.plan(1);
for (var i = 0; i < lines.length; i++) {
......
var tap = require('tap');
var redis = require('redis');
var moment = require('moment');
var Harbinger = require('../index');
tap.test('digest', function(test) {
setUp: function(callback) {
var redisClient = this.redisClient = redis.createClient(6379, 'redis');
redisClient.on("error", function (err) {
var redisClient = redis.createClient(6379, 'redis');
redisClient.on("error", function (err) {
console.log("Error " + err);
});
redisClient.on("end", function(err) {
});
redisClient.on("end", function(err) {
//console.log("Redis connection closed");
});
});
var series = function(func, thisarg, args, callback) {
var out = [];
var trap = function(err) {
if (err) {
// What
callback(err);
return;
}
var result = Array.prototype.slice.call(arguments);
result.shift();
out.push( result );
next();
};
var next = function() {
// Get next args array
var arg;
if (args.length == 0) {
callback(null, out);
return;
}
arg = args.shift();
// Make sure last arg is our callback
arg.push( trap );
//console.log('calling ', arg);
callback();
},
tearDown: function(callback) {
this.redisClient.quit();
callback();
},
func.apply(thisarg, arg);
};
count: {
single: function(test) {
next();
};
tap.test('timeseries.count.single', function(test) {
var self = this;
var ts = new Harbinger.Timeseries(this.redisClient, 60, 'testing');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing');
var secondsBucket = moment().unix() - 100;
test.expect(2);
test.plan(2);
ts.count(secondsBucket, 3, function(err) {
if (err) {
......@@ -45,23 +73,19 @@ tap.test('digest', function(test) {
test.done();
});
});
},
// Calculate Error Rate every second, alert if rate goes above N
/*
To calculate the error rate, we have to read from multiple keys. Can use Redis mget command to do so
*/
bla: function(test) {
test.done();
},
});
multiple: function(test) {
// Calculate Error Rate every second, alert if rate goes above N
/*
To calculate the error rate, we have to read from multiple keys. Can use Redis mget command to do so
*/
tap.test('timeseries.getCounts', function(test) {
var self = this;
var ts = new Harbinger.Timeseries(this.redisClient, 60, 'testing2');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing2');
var secondsBucket = moment().unix() - 200;
test.expect(2);
test.plan(2);
series(
Harbinger.Timeseries.prototype.count,
......@@ -94,13 +118,15 @@ tap.test('digest', function(test) {
}
);
},
statistics: function(test) {
});
tap.test('timeseries.getCountStatistics', function(test) {
var self = this;
var ts = new Harbinger.Timeseries(this.redisClient, 60, 'testing2');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing2');
var secondsBucket = moment().unix() - 300;
test.expect(4);
test.plan(4);
series(
Harbinger.Timeseries.prototype.count,
......@@ -133,18 +159,15 @@ tap.test('digest', function(test) {
}
);
}
});
},
times: function (test) {
tap.test('timeseries.getTimes', function(test) {
var self = this;
var ts = new Harbinger.Timeseries(this.redisClient, 60, 'testing-times');
var ts = new Harbinger.Timeseries(redisClient, 60, 'testing-times');
var secondsBucket = moment().unix() - 200;
test.expect(2);
test.plan(2);
series(
Harbinger.Timeseries.prototype.time,
......@@ -156,7 +179,7 @@ tap.test('digest', function(test) {
function(err, out) {
if (err) {
console.log('Err', err);
test.done();
test.end();
return;
}
test.ok(true);
......@@ -167,18 +190,15 @@ tap.test('digest', function(test) {
function(err, out) {
if (err) {
console.log('Err2', err);
test.done();
test.end();
return;
}
test.equals( out.join(','), '200,900');
test.done();
test.end();
}
);
}
);
}
});
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