This repository has been archived by the owner on Jan 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to try to identify file descriptor leaks across nginx reloads
See: 18F/api.data.gov#188
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |