Windshaft-cartodb/test/unit/stats/reporter/named-map-provider-test.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
const assert = require('assert');
2019-10-07 17:29:07 +08:00
const NamedMapProviderReporter = require('../../../../lib/stats/reporter/named-map-provider');
describe('named-map-provider-reporter', function () {
it('should report metrics every 100 ms', function (done) {
const oldStatsClient = global.statsClient;
global.statsClient = {
gauge: function (metric, value) {
this[metric] = value;
}
};
const dummyCacheEntries = [
{
k: 'foo:template_1',
2019-10-22 01:07:24 +08:00
v: { instantiation_1: 1 }
},
{
k: 'bar:template_2',
2019-10-22 01:07:24 +08:00
v: { instantiation_1: 1, instantiation_2: 2 }
},
{
k: 'buz:template_3',
2019-10-22 01:07:24 +08:00
v: { instantiation_1: 1, instantiation_2: 2, instantiation_3: 3 }
}
];
const reporter = new NamedMapProviderReporter({
namedMapProviderCache: {
providerCache: {
dump: () => dummyCacheEntries,
length: dummyCacheEntries.length
}
},
intervalInMilliseconds: 100
});
reporter.start();
setTimeout(() => {
reporter.stop();
assert.strictEqual(
global.statsClient['windshaft.named-map-provider-cache.named-map.count'],
3
);
assert.strictEqual(
2019-09-16 19:09:23 +08:00
global.statsClient['windshaft.named-map-provider-cache.named-map.instantiation.count'],
6
);
global.statsClient = oldStatsClient;
done();
}, 110);
});
});