Skip to content
This repository has been archived by the owner on Jan 7, 2018. It is now read-only.

Commit

Permalink
Add a test to try to identify file descriptor leaks across nginx reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Feb 24, 2015
1 parent 8fa5fa6 commit d16c002
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions test/integration/processes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

require('../test_helper');

var _ = require('lodash'),
apiUmbrellaConfig = require('api-umbrella-config'),
async = require('async'),
execFile = require('child_process').execFile,
Factory = require('factory-lady'),
fs = require('fs'),
ipaddr = require('ipaddr.js'),
mongoose = require('mongoose'),
path = require('path'),
processEnv = require('../../lib/process_env'),
request = require('request'),
Tail = require('tail').Tail;

var config = apiUmbrellaConfig.load(path.resolve(__dirname, '../config/test.yml'));

describe('server processes', function() {
describe('nginx', function() {
it('does not leak file descriptors across reloads', function(done) {
this.timeout(30000);

var configPath = processEnv.supervisordConfigPath();
var execOpts = { env: processEnv.env() };
execFile('supervisorctl', ['-c', configPath, 'pid', 'router-nginx'], execOpts, function(error, stdout, stderr) {
if(error) {
return done('Error fetching nginx pid: ' + error.message + '\n\nSTDOUT: ' + stdout + '\n\nSTDERR:' + stderr);
}

var parentPid = stdout.trim();

async.timesSeries(10, function(index, next) {
execFile('supervisorctl', ['-c', configPath, 'kill', 'HUP', 'router-nginx'], execOpts, function(error, stdout, stderr) {
if(error) {
return next('Error reloading nginx: ' + error.message + '\n\nSTDOUT: ' + stdout + '\n\nSTDERR:' + stderr);
}

setTimeout(function() {
execFile('lsof', ['-R', '-c', 'nginx'], execOpts, function(error, stdout, stderr) {
if(error) {
return next('Error gathering lsof details: ' + error.message + '\n\nSTDOUT: ' + stdout + '\n\nSTDERR:' + stderr);
}

var lines = _.filter(stdout.split('\n'), function(line) {
var columns = line.split(/\s+/);
return columns[2] == parentPid;
});
setTimeout(function() {
next(null, lines.length);
}, 500);
});
}, 500);
});
}, function(error, descriptorCounts) {
if(error) {
return done(error);
}

_.uniq(descriptorCounts).length.should.eql(1);
done();
});
});
});
});
});

0 comments on commit d16c002

Please sign in to comment.