it('verify publish interval publishes the proper data while reset clears the data', callback => { // Configure the telemetry API such that on the first second we get a publish, then in the second second we // get a reset, then in the 3rd we get another publish TelemetryAPI.init(_createConfig({ publishInterval: 1, resetInterval: 2 }), err => { assert.ok(!err); // Note that if this takes longer than one second our test fails intermittently :( I'm not sure we can avoid this // without disrupting the test Telemetry.incr('incr', 10); Telemetry.append('append', 50); Telemetry.append('append', 30); // Wait 1s for the publish event to verify the published data TelemetryAPI.emitter.once('publish', data => { assert.strictEqual(data.tests.incr, 10); assert.strictEqual(data.tests.append.length, 2); assert.strictEqual(data.tests.append[0], 50); assert.strictEqual(data.tests.append[1], 30); // Once we get our reset, wait for the next publish to ensure our counts are reset TelemetryAPI.emitter.once('reset', () => { TelemetryAPI.emitter.once('publish', data => { // Either the top-level tests module object should be gone, or the incr key should either be 0 or falsey assert.ok(!data.tests || !data.tests.incr); // Either the top-level tests module object should be gone, or the append key histograms should be either falsey or empty assert.ok(!data.tests || !data.tests.append || !data.tests.append.length); return callback(); }); }); }); }); });
before(function(callback) { // Fill up the global admin rest context globalAdminRestContext = TestsUtil.createGlobalAdminRestContext(); // Enable the telemetry API TelemetryAPI.init({'enabled': true}, function(err) { assert.ok(!err); return callback(); }); });
beforeEach(callback => { // Reset the telemetry configuration before each telemetry test TelemetryAPI.init(_createConfig(), () => { // *Force* a reset of all telemetry values, even if it is not time to do so TelemetryAPI.reset(err => { assert.ok(!err); Telemetry = TelemetryAPI.telemetry('tests'); return callback(); }); }); });
after(function(callback) { TelemetryAPI.init({'enabled': false}, function(err) { assert.ok(!err); return callback(); }); });