Permalink
Browse files

Optional predictable campaign URLs

  • Loading branch information...
1 parent fc0dfaf commit fa86c08f4fd3f65336336b4cffcd280c471aee97 @jakub-g jakub-g committed with divdavem Sep 17, 2013
Showing with 27 additions and 8 deletions.
  1. +2 −0 README.md
  2. +6 −4 bin/attester.js
  3. +10 −1 lib/attester/campaign.js
  4. +1 −0 lib/attester/config.js
  5. +1 −0 lib/attester/server.js
  6. +2 −1 lib/test-campaign/campaign.js
  7. +5 −2 lib/test-server/server.js
View
@@ -267,6 +267,8 @@ This is used by the [junit bridge](https://github.com/attester/attester-junit).
`--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.
+`--predictable-urls <boolean>` If true, resources served by the campaign have predictable URLs (campaign1, campaign2...). Otherwise, the campaign part in the URL is campaign ID.
+
**Configuration file options**
Any option configurable through the configuration file can also be specified from the command line with the `--config` prefix.
View
@@ -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', 'shutdown-on-campaign-end']).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', 'predictable-urls']).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.',
@@ -35,6 +35,7 @@ var opt = optimist.usage('Usage: $0 [options] [config.yml|config.json]').boolean
'phantomjs-instances': 'Number of instances of PhantomJS to start.',
'phantomjs-path': 'Path to PhantomJS executable.',
'port': 'Port used for the web server. If set to 0, an available port is automatically selected.',
+ 'predictable-urls': 'If true, resources served by the campaign have predictable URLs (campaign1, campaign2...). Otherwise, the campaign part in the URL is campaign ID. Useful for debugging.',
'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.',
@@ -66,12 +67,13 @@ if (argv.env) {
}
attester.config.set(filtered);
+// argv._ is an array of file names to read campaign information from
if (argv._.length === 0) {
// Didn't specify a file, run a campaign with values from the config
- attester.campaign.create({}, argv.config);
+ attester.campaign.create({}, argv.config, 1);
} else {
- argv._.forEach(function (campaign) {
- attester.campaign.create(attester.config.readFile(campaign), argv.config);
+ argv._.forEach(function (campaign, n) {
+ attester.campaign.create(attester.config.readFile(campaign), argv.config, n+1);
});
}
@@ -48,7 +48,13 @@ var getDefaults = function () {
};
};
-campaign.create = function (campaign, override) {
+/**
+ * @param {Object} campaign configuration object
+ * @param {Object} override configuration object
+ * @param {Number} campaignNumber Used if predictableUrls option was enabled.
+ * @return {Object} JSON with campaign configuration
+ */
+campaign.create = function (campaign, override, campaignNumber) {
var campaignConfig = getDefaults();
if (override && override.resources) {
// "array-ify" entries in resources so they can get merged properly
@@ -60,6 +66,9 @@ campaign.create = function (campaign, override) {
}
merge(campaignConfig, campaign);
merge(campaignConfig, override || {});
+ campaignConfig.predictableUrls = attester.config['predictable-urls'];
+ campaignConfig.campaignNumber = campaignNumber;
+
var json = attester.config.parse(campaignConfig);
attester.event.emit("campaign.create", json);
@@ -34,6 +34,7 @@ exports.getDefaults = function () {
'phantomjs-instances': process.env.npm_package_config_phantomjsInstances || 0,
'phantomjs-path': 'phantomjs',
'port': 7777,
+ 'predictable-urls': false,
'shutdown-on-campaign-end': true,
'slow-test-threshold': 2500,
'task-timeout': 5 * 60 * 1000 // 5 minutes
@@ -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({
+ predictableUrls: config["predictable-urls"],
shutdownOnCampaignEnd: config["shutdown-on-campaign-end"],
frozen: config["server-only"],
flashPolicyPort: config["flash-policy-port"],
@@ -40,8 +40,9 @@ var createCampaignId = function (date) {
var TestCampaign = function (config, parentLogger) {
this.startTime = new Date();
+ this.campaignNumber = config.campaignNumber;
this.id = createCampaignId(this.startTime);
- this.baseURL = "/" + this.id;
+ this.baseURL = "/campaign" + (config.predictableUrls ? this.campaignNumber : this.id);
this.logger = new Logger('TestCampaign', this.id, parentLogger);
this.logger.logInfo("Initializing campaign...");
@@ -59,7 +59,8 @@ var routeToCampaign = function (req, res, next) {
res.end();
return;
}
- var campaignIdMatch = req.url.match(/^\/([0-9]+)\//);
+
+ var campaignIdMatch = req.url.match(/^\/campaign([0-9]+)\//);
var campaign = campaignIdMatch ? testServer.findCampaign(campaignIdMatch[1]) : null;
if (!campaign) {
return next();
@@ -280,7 +281,9 @@ TestServer.prototype.findCampaign = function (campaignId) {
var campaigns = this.campaigns;
for (var i = 0, l = campaigns.length; i < l; i++) {
var curCampaign = campaigns[i];
- if (curCampaign.id == campaignId) {
+ // campaignNumber is used if predictableUrls == true. The values are 1, 2, 3...
+ // campaign id's values OTOH are timestamps, so there's no risk of collision.
+ if (curCampaign.id == campaignId || curCampaign.campaignNumber == campaignId) {
return curCampaign;
}
}

0 comments on commit fa86c08

Please sign in to comment.