2019-09-14 02:01:03 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const assert = require('assert');
|
2019-10-07 17:29:07 +08:00
|
|
|
const NamedMapProviderReporter = require('../../../../lib/stats/reporter/named-map-provider');
|
2019-09-14 02:01:03 +08:00
|
|
|
|
|
|
|
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 }
|
2019-09-14 02:01:03 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
k: 'bar:template_2',
|
2019-10-22 01:07:24 +08:00
|
|
|
v: { instantiation_1: 1, instantiation_2: 2 }
|
2019-09-14 02:01:03 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
k: 'buz:template_3',
|
2019-10-22 01:07:24 +08:00
|
|
|
v: { instantiation_1: 1, instantiation_2: 2, instantiation_3: 3 }
|
2019-09-14 02:01:03 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
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'],
|
2019-09-14 02:01:03 +08:00
|
|
|
6
|
|
|
|
);
|
|
|
|
|
|
|
|
global.statsClient = oldStatsClient;
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 110);
|
|
|
|
});
|
|
|
|
});
|