From 3f7202d89c698878bfd39a441247ce09d5d338bc Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 14 Sep 2015 19:07:53 +0200 Subject: [PATCH] Port tests for stats --- Makefile | 2 + test/unit/cartodb/ported/profiler.test.js | 17 ++++++++ test/unit/cartodb/ported/stats_client.test.js | 40 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 test/unit/cartodb/ported/profiler.test.js create mode 100644 test/unit/cartodb/ported/stats_client.test.js diff --git a/Makefile b/Makefile index 3f6ebf43..5ca7973a 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ test: config/environments/test.js @echo "***tests***" @$(SHELL) ./run_tests.sh ${RUNTESTFLAGS} \ test/unit/cartodb/*.js \ + test/unit/cartodb/ported/*.js \ test/unit/cartodb/cache/model/*.js \ test/integration/*.js \ test/acceptance/*.js \ @@ -33,6 +34,7 @@ test-unit: config/environments/test.js @echo "***tests***" @$(SHELL) ./run_tests.sh ${RUNTESTFLAGS} \ test/unit/cartodb/*.js \ + test/unit/cartodb/ported/*.js \ test/unit/cartodb/cache/model/*.js test-integration: config/environments/test.js diff --git a/test/unit/cartodb/ported/profiler.test.js b/test/unit/cartodb/ported/profiler.test.js new file mode 100644 index 00000000..29d9b485 --- /dev/null +++ b/test/unit/cartodb/ported/profiler.test.js @@ -0,0 +1,17 @@ +require('../../../support/test_helper'); + +var assert = require('assert'); +var ProfilerProxy = require('../../../../lib/cartodb/stats/profiler_proxy'); + +describe('profiler', function() { + + it('Profiler is null in ProfilerProxy when profiling is not enabled', function() { + var profilerProxy = new ProfilerProxy({profile: false}); + assert.equal(profilerProxy.profiler, null); + }); + + it('Profiler is NOT null in ProfilerProxy when profiling is enabled', function() { + var profilerProxy = new ProfilerProxy({profile: true}); + assert.notEqual(profilerProxy.profiler, null); + }); +}); diff --git a/test/unit/cartodb/ported/stats_client.test.js b/test/unit/cartodb/ported/stats_client.test.js new file mode 100644 index 00000000..088206a0 --- /dev/null +++ b/test/unit/cartodb/ported/stats_client.test.js @@ -0,0 +1,40 @@ +require('../../../support/test_helper'); + +var assert = require('assert'); + +var StatsClient = require('../../../../lib/cartodb/stats/client'); + +describe('stats client', function() { + var statsInstance; + + before(function() { + statsInstance = StatsClient.instance; + StatsClient.instance = null; + }); + + after(function() { + StatsClient.instance = statsInstance; + }); + + it('reports errors when they repeat', function(done) { + var WADUS_ERROR = 'wadus_error'; + var statsClient = StatsClient.getInstance({ host: '127.0.0.1', port: 8033 }); + + statsClient.socket.emit('error', 'other_error'); + assert.ok(statsClient.last_error); + assert.equal(statsClient.last_error.msg, 'other_error'); + assert.ok(!statsClient.last_error.interval); + + statsClient.socket.emit('error', WADUS_ERROR); + assert.ok(statsClient.last_error); + assert.equal(statsClient.last_error.msg, WADUS_ERROR); + assert.ok(!statsClient.last_error.interval); + + statsClient.socket.emit('error', WADUS_ERROR); + assert.ok(statsClient.last_error); + assert.equal(statsClient.last_error.msg, WADUS_ERROR); + assert.ok(statsClient.last_error.interval); + + done(); + }); +});