Skip to content

Commit

Permalink
Increase preprocessors timeouts to 2s
Browse files Browse the repository at this point in the history
  • Loading branch information
joanniclaborde committed Nov 25, 2014
1 parent c6a7d55 commit a76bf52
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 27 deletions.
5 changes: 3 additions & 2 deletions lib/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ Preprocessor.setWorkers = function(){
workers = workerFarm({
maxCallsPerWorker: 100,
maxConcurrentWorkers: 4,
maxConcurrentCallsPerWorker: -1,
maxCallTime: 1000
maxConcurrentCallsPerWorker: Infinity,
maxCallTime: 2000,
forcedKillTime: 0 // Preprocessors don't listen to system messages, just kill them
}, require.resolve('./preprocessor_worker.js'));
};

Expand Down
27 changes: 7 additions & 20 deletions lib/preprocessor_worker.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
const TIMEOUT = 5 * 1000;

module.exports = function( context, preprocessor_path, cb ){

var preprocess_timeout = setTimeout( function(){
console.log('process committing suicide');
process.exit();
}, TIMEOUT );

var error;
module.exports = function(context, preprocessor_path, callback) {
try {
var preprocessor = require( preprocessor_path );
context = preprocessor( context );
} catch( err ){
error = err;
} finally {
clearTimeout( preprocess_timeout );
if( error ) return cb( error, null );
return cb( null, context );
var preprocessor = require(preprocessor_path);
context = preprocessor(context);
} catch (err) {
return callback(err);
}

};
callback(null, context);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"glob": "~3.2.6",
"handlebars": "~1.0.12",
"handlebars-helper": "~0.0.9",
"worker-farm": "~0.3.1",
"worker-farm": "~1.1.0",
"raven": "^0.6.2",
"socket.io": "~1.0.6",
"continuation-local-storage": "~3.1.1"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/site 1/preprocessors/infinite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function(context) {
while (true);
context.test = true;
return context;
};
File renamed without changes.
4 changes: 0 additions & 4 deletions test/fixtures/site1/preprocessors/infinite.js

This file was deleted.

4 changes: 4 additions & 0 deletions test/solidus.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ describe( 'Solidus', function(){
});

it( 'Preprocesses the context of pages', function( done ){
this.timeout(3000); // /infinite.json should timeout after 2s
var s_request = request( solidus_server.router );
async.parallel([
function( callback ){
s_request.get('/.json')
.expect( 'Content-Type', /json/ )
.expect( 200 )
.end( function( err, res ){
if( err ) throw err;
assert( res.body.test === true );
callback( err );
});
Expand All @@ -278,11 +280,13 @@ describe( 'Solidus', function(){
.expect( 'Content-Type', /json/ )
.expect( 200 )
.end( function( err, res ){
if( err ) throw err;
assert( !res.body.test );
s_request.get('/.json')
.expect( 'Content-Type', /json/ )
.expect( 200 )
.end( function( err, res ){
if( err ) throw err;
assert( res.body.test === true );
callback( err );
});
Expand Down

0 comments on commit a76bf52

Please sign in to comment.