Skip to content

Commit

Permalink
Update tests to run with expresso 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonjlee committed Dec 2, 2010
1 parent c05329f commit c9f2593
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"preinstall": "make clean compile"
},
"devDependencies": {
"expresso": ">=0.6.4"
"expresso": ">=0.7.0"
},
"dependencies": {
}
Expand Down
7 changes: 4 additions & 3 deletions test/http.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var http = require('http'),
var assert = require('assert'),
http = require('http'),
nlconfig = require('../lib/config').disableServer(),
HttpServer = require('../lib/http').HttpServer;

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;
Expand All @@ -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');
Expand Down
21 changes: 11 additions & 10 deletions test/loop.test.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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(); },
Expand All @@ -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(); },
Expand All @@ -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(); },
Expand All @@ -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(); },
Expand All @@ -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(); },
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions test/monitoring.test.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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'),
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions test/remote.test.js
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
7 changes: 4 additions & 3 deletions test/reporting.test.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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');
Expand All @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions test/stats.test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions test/util.test.js
Original file line number Diff line number Diff line change
@@ -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),
Expand Down

0 comments on commit c9f2593

Please sign in to comment.