Skip to content

Commit

Permalink
Refactor round robin test
Browse files Browse the repository at this point in the history
  • Loading branch information
skomski committed Mar 5, 2012
1 parent 5bd1671 commit f875593
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 60 deletions.
5 changes: 3 additions & 2 deletions lib/up.js
Expand Up @@ -56,9 +56,10 @@ UpServer.prototype.__proto__ = Distributor.prototype;

UpServer.prototype.terminate = function (fn) {
this.terminated = true;
var terminates = [].concat(this.workers);

for (var i = 0, l = this.workers.length; i < l; i++) {
this.workers[i].shutdown();
for (var i = 0, l = terminates.length; i < l; i++) {
terminates[i].shutdown();
}

this.server.close(fn);
Expand Down
58 changes: 0 additions & 58 deletions test/up.js
Expand Up @@ -8,64 +8,6 @@ var up = require('../lib/up')

describe('up', function () {

it('should load the workers', function (done) {
var httpServer = http.Server().listen(6000, onListen)
, srv = up(httpServer, __dirname + '/server')

function onListen (err) {
if (err) return done(err);
request.get('http://localhost:6000', function (res) {
var pid = res.body.pid;
expect(pid).to.be.a('number');
done();
});
}
});

it('should round-robin the workers', function (done) {
var httpServer = http.Server().listen(6001, onListen)
, srv = up(httpServer, __dirname + '/server', { numWorkers: 2 })

function onListen (err) {
if (err) return done(err);

srv.on('spawn', function () {
// count workers
if (2 != srv.workers.length) return;

request.get('http://localhost:6001', function (res) {
var pid1 = res.body.pid;
expect(pid1).to.be.a('number');

request.get('http://localhost:6001', function (res) {
var pid2 = res.body.pid;
expect(pid2).to.be.a('number');
expect(pid2).to.not.equal(pid1);

request.get('http://localhost:6001', function (res) {
expect(res.body.pid).to.equal(pid1);

request.get('http://localhost:6001', function (res) {
expect(res.body.pid).to.equal(pid2);
done();
});
});
});
});
});
}
});

it('should expose ports and procs as public api', function (done) {
var httpServer = http.Server().listen()
, srv = up(httpServer, __dirname + '/server', { numWorkers: 2 })

srv.once('spawn', function () {
expect(srv.workers).to.have.length(1);
done();
});
});

it('should reload workers', function (done) {
var httpServer = http.Server().listen(6002, onListen)
, srv = up(httpServer, __dirname + '/server', { numWorkers: 2 })
Expand Down

0 comments on commit f875593

Please sign in to comment.