Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
max_requests_per_child test
Browse files Browse the repository at this point in the history
  • Loading branch information
mash committed Sep 18, 2012
1 parent 478f8ee commit dde35cd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -3,3 +3,4 @@
test:
node ./test/01_restart_app.js
node ./test/02_accidental_death.js
node ./test/03_max_requests_per_child.js
65 changes: 65 additions & 0 deletions test/03_max_requests_per_child.js
@@ -0,0 +1,65 @@
var fs = require('fs'),
assert = require('assert'),
http = require('http'),
cluster = require('cluster'),
async = require('async'),
angel = require('../angel'),
app = require('./_app.js');

// this will be our test app's response body
var expected_body = process.env.NODE_ANGEL_TEST_MESSAGE = "Hello";

var test_port = 3000;

angel( app, {
port: test_port, // mmm, test requires port 3000 to be open
workers: 1,
max_requests_per_child: 2,
} );

function sendRequest( callback ) {
http.get({
host: 'localhost',
port: test_port,
path: '/'
}, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
callback( body );
});
});
}

function runTest () {
var jobs = []
, requests_count = 10;
while ( requests_count -- ) {
jobs.push( function(callback) {
sendRequest( function(body) {
callback( null, body );
});
});
}
async.series( jobs, function (err, results) {
assert( err === null, 'no errors' );

var worker_pids = {};
results.forEach( function( result ) {
worker_pids[ result.split(/:/).pop() ] = 1;
});
assert( Object.keys( worker_pids ).length === 5,
'10 requests to 1 worker with 2 max_requests_per_child -> 5' );

console.log( 'Result: PASS' );

process.exit(0);
});
}

if ( cluster.isMaster ) {
// wait til listening
setTimeout( runTest, 100 );
}

0 comments on commit dde35cd

Please sign in to comment.