From 1fac29f34dd062838dad2017b70b9dc4aabc0e5c Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Mon, 5 Jun 2017 11:45:03 -0500 Subject: [PATCH] Add a test --- test/librato_tests.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/librato_tests.js b/test/librato_tests.js index 1bde1eb..74d9460 100644 --- a/test/librato_tests.js +++ b/test/librato_tests.js @@ -5,6 +5,7 @@ const serverPort = 36001; const librato = require('../lib/librato.js'); const nock = require('nock'); const sinon = require('sinon'); +const http = require('http'); const config = { debug: false, @@ -94,10 +95,12 @@ module.exports.tags = { .defaultReplyHeaders({'Content-Type': 'application/json'}); librato.init(null, config, this.emitter); + this.httpSpy = sinon.spy(http, 'request'); callback(); }, tearDown: function(callback) { + http.request.restore(); callback(); }, @@ -262,6 +265,36 @@ module.exports.tags = { this.emitter.emit('flush', 123, metrics); }, + testBatchProperFlushes: function(test) { + test.expect(4); + var gauges = {}; + for (var i = 0; i < 500; i++) { + var key = 'gauge' + i; + gauges[key] = 1; + } + var metrics = {gauges: gauges}; + this.apiServer.post('/v1/measurements') + .reply(200, (uri, requestBody) => { + test.ok(requestBody.measurements); + // Should be one submission because we hit our maxBatchSize + test.ok(this.httpSpy.calledOnce); + }); + + this.emitter.emit('flush', 123, metrics); + + setTimeout(() => { + this.httpSpy.reset(); + this.apiServer.post('/v1/measurements') + .reply(200, (uri, requestBody) => { + test.ok(requestBody.measurements); + // Should be one submission because we hit our maxBatchSize + test.ok(this.httpSpy.calledOnce); + test.done(); + }); + this.emitter.emit('flush', 123, metrics); + }, 500); + }, + testValidMeasurementTopLevelTag: function(test) { config.librato.host = '127.0.0.1'; config.librato.tags = {test: true};