2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2015-09-17 19:40:01 +08:00
|
|
|
|
|
|
|
var assert = require('assert');
|
2019-10-07 15:40:50 +08:00
|
|
|
var StatsClient = require('../../lib/stats/client');
|
2019-10-07 16:01:18 +08:00
|
|
|
var ProfilerProxy = require('../../lib/stats/profiler-proxy');
|
2015-09-17 19:40:01 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('profiler + statsd', function () {
|
2015-09-17 19:40:01 +08:00
|
|
|
var statsInstance;
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
before(function () {
|
2015-09-17 19:40:01 +08:00
|
|
|
statsInstance = StatsClient.instance;
|
|
|
|
StatsClient.instance = null;
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
after(function () {
|
2015-09-17 19:40:01 +08:00
|
|
|
StatsClient.instance = statsInstance;
|
|
|
|
});
|
|
|
|
|
|
|
|
var statsdConfig = {
|
|
|
|
host: 'whoami.vizzuality.com',
|
|
|
|
port: 8125,
|
|
|
|
prefix: 'test.',
|
|
|
|
cacheDns: false
|
|
|
|
// support all allowed node-statsd options
|
|
|
|
};
|
|
|
|
|
|
|
|
// See https://github.com/CartoDB/Windshaft/issues/167
|
2019-10-22 01:07:24 +08:00
|
|
|
it('profiler does not throw uncaught exception on invalid host/port', function (done) {
|
2015-09-17 19:40:01 +08:00
|
|
|
var statsClient = StatsClient.getInstance(statsdConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
var profiler = new ProfilerProxy({ profile: true, statsd_client: statsClient });
|
2015-09-17 19:40:01 +08:00
|
|
|
|
|
|
|
profiler.start('test');
|
|
|
|
profiler.done('wadus');
|
|
|
|
profiler.end();
|
|
|
|
|
|
|
|
profiler.sendStats();
|
|
|
|
|
|
|
|
// force a call to validate sendStats does not throw and uncaught exception
|
2019-10-22 01:07:24 +08:00
|
|
|
statsClient.timing('forced', 50, 1, function (err) {
|
2015-09-17 19:40:01 +08:00
|
|
|
assert.ok(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(err.code, 'ENOTFOUND');
|
2015-09-17 19:40:01 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|