From c9f259326ed5318ed4d9a7eb695469998c439c1a Mon Sep 17 00:00:00 2001 From: Jonathan Lee Date: Wed, 1 Dec 2010 22:02:04 -0500 Subject: [PATCH] Update tests to run with expresso 0.7.0 --- package.json | 2 +- test/http.test.js | 7 ++++--- test/loop.test.js | 21 +++++++++++---------- test/monitoring.test.js | 15 ++++++++------- test/remote.test.js | 5 +++-- test/reporting.test.js | 7 ++++--- test/stats.test.js | 7 ++++--- test/util.test.js | 5 +++-- 8 files changed, 38 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index fb55e58..588abca 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "preinstall": "make clean compile" }, "devDependencies": { - "expresso": ">=0.6.4" + "expresso": ">=0.7.0" }, "dependencies": { } diff --git a/test/http.test.js b/test/http.test.js index 75e9a84..f84e284 100644 --- a/test/http.test.js +++ b/test/http.test.js @@ -1,4 +1,5 @@ -var http = require('http'), +var assert = require('assert'), + http = require('http'), nlconfig = require('../lib/config').disableServer(), HttpServer = require('../lib/http').HttpServer; @@ -6,7 +7,7 @@ var server = new HttpServer().start(9020); setTimeout(function() { server.stop(); }, 1500); module.exports = { - 'example: add a new route': function(assert, beforeExit) { + 'example: add a new route': function(beforeExit) { var done = false; server.addRoute('^/route', function() { done = true; @@ -20,7 +21,7 @@ module.exports = { assert.ok(done, 'Never got request to /route'); }); }, - 'test file server finds package.json': function(assert, beforeExit) { + 'test file server finds package.json': function(beforeExit) { var done = false; var client = http.createClient(9020, '127.0.0.1'), req = client.request('GET', '/package.json'); diff --git a/test/loop.test.js b/test/loop.test.js index fbb7969..419fcfb 100644 --- a/test/loop.test.js +++ b/test/loop.test.js @@ -1,9 +1,10 @@ -var loop = require('../lib/loop'), +var assert = require('assert'), + loop = require('../lib/loop'), Loop = loop.Loop, MultiLoop = loop.MultiLoop; module.exports = { - 'example: a basic rps loop with set duration': function(assert, beforeExit) { + 'example: a basic rps loop with set duration': function(beforeExit) { var i = 0, start = new Date(), lasttime = start, duration, l = new Loop({ fun: function(finished) { @@ -26,7 +27,7 @@ module.exports = { assert.ok(Math.abs(duration - 1000) <= 60, '1000 == ' + duration); }); }, - 'example: use Scheduler to vary execution rate and concurrency': function (assert, beforeExit) { + 'example: use Scheduler to vary execution rate and concurrency': function (beforeExit) { var i = 0, c = 0, start = new Date(), duration, l = new MultiLoop({ fun: function(finished) { i++; finished(); }, @@ -43,7 +44,7 @@ module.exports = { assert.ok(Math.abs(duration - 3500) < 500, '3500 == ' + duration); }); }, - 'test numberOfTimes loop': function(assert, beforeExit) { + 'test numberOfTimes loop': function(beforeExit) { var i = 0, l = new Loop({ fun: function(finished) { i++; finished(); }, @@ -55,7 +56,7 @@ module.exports = { assert.equal(3, i, 'loop executed incorrect number of times'); }); }, - 'test emits start and stop events': function(assert, beforeExit) { + 'test emits start and stop events': function(beforeExit) { var started, ended, l = new Loop({ fun: function(finished) { finished(); }, @@ -72,7 +73,7 @@ module.exports = { }); }, - 'test concurrency': function(assert, beforeExit) { + 'test concurrency': function(beforeExit) { var i = 0, start = new Date(), duration, l = new MultiLoop({ fun: function(finished) { i++; finished(); }, @@ -90,7 +91,7 @@ module.exports = { assert.ok(Math.abs(duration - 1000) < 30, '1000 == ' + duration); }); }, - 'MultiLoop emits events': function(assert, beforeExit) { + 'MultiLoop emits events': function(beforeExit) { var started = false, ended = false, l = new MultiLoop({ fun: function(finished) { finished(); }, @@ -105,7 +106,7 @@ module.exports = { assert.ok(ended, 'end never emitted'); }); }, - 'change loop rate': function(assert, beforeExit) { + 'change loop rate': function(beforeExit) { var i = 0, start = new Date(), duration, l = new Loop({ fun: function(finished) { @@ -121,12 +122,12 @@ module.exports = { setTimeout(function() { l.rps = 20; }, 1500); beforeExit(function() { - assert.equal(i, 20, 'loop executed incorrect number of times: ' + i); // 5+10/2+20/2 == 20 + assert.ok(Math.abs(20 - i) <= 1, 'loop executed incorrect number of times: ' + i); // 5+10/2+20/2 == 20 assert.ok(!l.running, 'loop still flagged as running'); assert.ok(Math.abs(duration - 2000) <= 50, '2000 == ' + duration); }); }, - 'test MultiLoop.getProfileValue_ works': function(assert) { + 'test MultiLoop.getProfileValue_ works': function() { var getProfileValue = loop.MultiLoop.prototype.getProfileValue_; assert.equal(getProfileValue(null, 10), 0); assert.equal(getProfileValue(null, 10), 0); diff --git a/test/monitoring.test.js b/test/monitoring.test.js index e175c3f..735dd67 100644 --- a/test/monitoring.test.js +++ b/test/monitoring.test.js @@ -1,6 +1,7 @@ /*jslint sub:true */ -var http = require('http'), +var assert = require('assert'), + http = require('http'), EventEmitter = require('events').EventEmitter, util = require('../lib/util'), monitoring = require('../lib/monitoring'), @@ -24,7 +25,7 @@ function mockConnection(callback) { } module.exports = { - 'example: track runtime of a function': function(assert, beforeExit) { + 'example: track runtime of a function': function(beforeExit) { var m = new Monitor('runtime'), f = function() { var ctx = m.start(), runtime = Math.floor(Math.random() * 100); @@ -44,7 +45,7 @@ module.exports = { assert.ok(summary.median > 0 && summary.median < 100); }); }, - 'example: use a MonitorGroup to organize multiple Monitors': function(assert, beforeExit) { + 'example: use a MonitorGroup to organize multiple Monitors': function(beforeExit) { var m = new MonitorGroup('runtime'), f = function() { var transactionCtx = m.start('transaction'); @@ -70,7 +71,7 @@ module.exports = { assert.ok(Math.abs(summary['operation']['runtime'].median - 25) <= 5); }); }, - 'example: use EventEmitter objects instead of interacting with MonitorGroup directly': function(assert, beforeExit) { + 'example: use EventEmitter objects instead of interacting with MonitorGroup directly': function(beforeExit) { function MonitoredObject() { EventEmitter.call(this); var self = this; @@ -104,7 +105,7 @@ module.exports = { assert.ok(Math.abs(opSummary.median - 25) <= 5, '25 == ' + opSummary.median); }); }, - 'use EventEmitter objects with Monitor': function(assert, beforeExit) { + 'use EventEmitter objects with Monitor': function(beforeExit) { function MonitoredObject() { EventEmitter.call(this); var self = this; @@ -131,7 +132,7 @@ module.exports = { assert.ok(summary.median > 0 && summary.median < 100, summary.median.toString()); }); }, - 'HTTP specific monitors': function(assert, beforeExit) { + 'HTTP specific monitors': function(beforeExit) { var q = 0, m = new Monitor('result-codes', 'uniques', 'request-bytes', 'response-bytes'), client = http.createClient(9000, 'localhost'), @@ -173,7 +174,7 @@ module.exports = { assert.ok(responseBytesSummary.total > 20); }); }, - 'monitor generates update events with interval and overall stats': function(assert, beforeExit) { + 'monitor generates update events with interval and overall stats': function(beforeExit) { var m = new Monitor('runtime'), intervals = 0, f = function() { diff --git a/test/remote.test.js b/test/remote.test.js index fd1a1fe..65febb8 100755 --- a/test/remote.test.js +++ b/test/remote.test.js @@ -1,11 +1,12 @@ -var http = require('http'), +var assert = require('assert'), + http = require('http'), remote = require('../lib/remote'), nlconfig = require('../lib/config').disableServer(), HttpServer = require('../lib/http').HttpServer, Cluster = remote.Cluster; module.exports = { - 'basic end-to-end cluster test': function(assert, beforeExit) { + 'basic end-to-end cluster test': function(beforeExit) { var testTimeout, cluster, masterSetupCalled, slaveSetupCalled = [], slaveFunCalled = [], master = new HttpServer().start(9030), diff --git a/test/reporting.test.js b/test/reporting.test.js index 1e4388e..e92849e 100644 --- a/test/reporting.test.js +++ b/test/reporting.test.js @@ -1,6 +1,7 @@ /*jslint sub:true */ -var nlconfig = require('../lib/config').disableServer(), +var assert = require('assert'), + nlconfig = require('../lib/config').disableServer(), reporting = require('../lib/reporting'), monitoring = require('../lib/monitoring'), REPORT_MANAGER = reporting.REPORT_MANAGER; @@ -19,7 +20,7 @@ function mockConnection(callback) { } module.exports = { - 'example: add a chart to test summary webpage': function(assert, beforeExit) { + 'example: add a chart to test summary webpage': function(beforeExit) { var report = REPORT_MANAGER.addReport('My Report'), chart1 = report.getChart('Chart 1'), chart2 = report.getChart('Chart 2'); @@ -42,7 +43,7 @@ module.exports = { assert.isNotNull(html.match('name":"'+chart2.name)); assert.isNotNull(html.match('summary":')); }, - 'example: update reports from Monitor and MonitorGroup stats': function(assert, beforeExit) { + 'example: update reports from Monitor and MonitorGroup stats': function(beforeExit) { var m = new monitoring.MonitorGroup('runtime') .initMonitors('transaction', 'operation'), f = function() { diff --git a/test/stats.test.js b/test/stats.test.js index f6cb805..98d64d5 100644 --- a/test/stats.test.js +++ b/test/stats.test.js @@ -1,7 +1,8 @@ -var stats = require('../lib/stats'); +var assert = require('assert'), + stats = require('../lib/stats'); module.exports = { - 'StatsGroup functions are non-enumerable': function(assert, beforeExit) { + 'StatsGroup functions are non-enumerable': function(beforeExit) { var s = new stats.StatsGroup(); s.latency = {}; assert.ok(s.get); @@ -14,7 +15,7 @@ module.exports = { } } }, - 'test StatsGroup methods': function(assert, beforeExit) { + 'test StatsGroup methods': function(beforeExit) { var s = new stats.StatsGroup(); s.latency = new stats.Histogram(); s.results = new stats.ResultsCounter(); diff --git a/test/util.test.js b/test/util.test.js index 44f5cc5..49c0d81 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -1,8 +1,9 @@ -var http = require('http'), +var assert = require('assert'), + http = require('http'), util = require('../lib/util'); module.exports = { - 'ReconnectingClient tolerates connection failures': function(assert, beforeExit) { + 'ReconnectingClient tolerates connection failures': function(beforeExit) { var PORT = 9010, simpleResponse = function (req, res) { res.writeHead(200); res.end(); }, svr = http.createServer(simpleResponse),