Skip to content

Commit

Permalink
Option to not shut down on campaign end
Browse files Browse the repository at this point in the history
Adds possibility to not shut down the server once campaign ends.
Useful for debugging.

Close #15. Close #54.
  • Loading branch information
jakub-g authored and divdavem committed Sep 25, 2013
1 parent 74dc386 commit fc0dfaf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -264,6 +264,9 @@ This is used by the [junit bridge](https://github.com/attester/attester-junit).

`--task-timeout` Maximum duration (in ms) for a test task.

`--shutdown-on-campaign-end <boolean>` When set to false, will not shut the server down nor exit the process upon finishing the campaign.
Might be useful for debugging.

**Configuration file options**

Any option configurable through the configuration file can also be specified from the command line with the `--config` prefix.
Expand Down
3 changes: 2 additions & 1 deletion bin/attester.js
Expand Up @@ -20,7 +20,7 @@ var exitProcess = require('../lib/exit-process.js');
var attester = require('../lib/attester.js');
var merge = require('../lib/merge.js');

var opt = optimist.usage('Usage: $0 [options] [config.yml|config.json]').boolean(['flash-policy-server', 'json-console', 'help', 'server-only', 'version', 'colors', 'ignore-errors', 'ignore-failures']).string(['phantomjs-path']).describe({
var opt = optimist.usage('Usage: $0 [options] [config.yml|config.json]').boolean(['flash-policy-server', 'json-console', 'help', 'server-only', 'version', 'colors', 'ignore-errors', 'ignore-failures', 'shutdown-on-campaign-end']).string(['phantomjs-path']).describe({
'browser': 'Path to any browser executable to execute the tests. Can be repeated multiple times.',
'colors': 'Uses colors (disable with --no-colors).',
'env': 'Environment configuration file. This file is available in the configuration object under env.',
Expand All @@ -36,6 +36,7 @@ var opt = optimist.usage('Usage: $0 [options] [config.yml|config.json]').boolean
'phantomjs-path': 'Path to PhantomJS executable.',
'port': 'Port used for the web server. If set to 0, an available port is automatically selected.',
'server-only': 'Only starts the web server, and configure it for the test campaign but do not start the campaign.',
'shutdown-on-campaign-end': 'Once the campaign is finished, shut down the server and exit the process. Set this to false to facilitate debugging.',
'slow-test-threshold': 'Threshold (in milliseconds) to mark long-running tests in the console report. Use 0 to disable.',
'task-timeout': 'Timeout of a task execution in milliseconds.',
'version': 'Displays the version number and exits.'
Expand Down
13 changes: 11 additions & 2 deletions lib/attester/cli.js
Expand Up @@ -28,13 +28,22 @@ exports.__init__ = function () {
};

function finish() {
endProcess(0);
checkConfigAndEndProcess(0);
}

function fail() {
endProcess(1);
checkConfigAndEndProcess(1);
}

function checkConfigAndEndProcess(code) {
if (attester.config["shutdown-on-campaign-end"]) {
endProcess(code);
} else {
attester.logger.logInfo("Idle; press CTRL-C to end the process.");
}
}


function endProcess(code) {
attester.event.emit("closing");
process.nextTick(function () {
Expand Down
1 change: 1 addition & 0 deletions lib/attester/config.js
Expand Up @@ -34,6 +34,7 @@ exports.getDefaults = function () {
'phantomjs-instances': process.env.npm_package_config_phantomjsInstances || 0,
'phantomjs-path': 'phantomjs',
'port': 7777,
'shutdown-on-campaign-end': true,
'slow-test-threshold': 2500,
'task-timeout': 5 * 60 * 1000 // 5 minutes
};
Expand Down
1 change: 1 addition & 0 deletions lib/attester/server.js
Expand Up @@ -40,6 +40,7 @@ exports.__init__ = function () {
// It is enough to have a single server, it should be able to serve multiple campaigns
exports.create = function (callback) {
testServer = new TestServer({
shutdownOnCampaignEnd: config["shutdown-on-campaign-end"],
frozen: config["server-only"],
flashPolicyPort: config["flash-policy-port"],
flashPolicyServer: config["flash-policy-server"],
Expand Down
4 changes: 3 additions & 1 deletion lib/test-server/server.js
Expand Up @@ -71,7 +71,9 @@ var routeToCampaign = function (req, res, next) {

var campaignFinished = function (campaign) {
var testServer = this;
arrayRemove(testServer.campaigns, campaign);
if (this.config.shutdownOnCampaignEnd) {
arrayRemove(testServer.campaigns, campaign);
}
testServer.assignTasks();
};

Expand Down

0 comments on commit fc0dfaf

Please sign in to comment.