Skip to content

Commit

Permalink
Add useProxy option to allow for literal paths.
Browse files Browse the repository at this point in the history
This is useful when Yeti is mounted to another
server and is being used to collect test results
for dynamic pages served by that server.

See attachServer.
  • Loading branch information
reid committed Mar 4, 2012
1 parent 36ef228 commit 2ea83d2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
18 changes: 14 additions & 4 deletions lib/client.js
Expand Up @@ -90,7 +90,13 @@ Client.prototype.handleBlizzardError = function (err) {
* Create and submit a batch of tests to the Hub.
*
* @method createBatch
* @param {Object} config Batch information. Must contain basedir (String) and tests (Array) properties.
* @param {Object} config Batch information.
* Must contain tests (Array) property.
* Must also contain either:
* - basedir (String) -- Root path for test filenames.
* - useProxy (Boolean) --
* True if tests are filenames to proxy to the Hub,
* false if they are literal URL pathnames.
* @return {ClientBatch} batch The new ClientBatch object.
*/
Client.prototype.createBatch = function (config) {
Expand All @@ -100,7 +106,7 @@ Client.prototype.createBatch = function (config) {
// TODO Refactor to make this impossible.
throw new Error("Session started too soon -- Yeti bug.");
}
return new ClientBatch(this.session, config.basedir, config.tests);
return new ClientBatch(this.session, config.basedir, config.tests, config.useProxy);
};

/**
Expand All @@ -112,8 +118,9 @@ Client.prototype.createBatch = function (config) {
* @param {BlizzardSession} session Connected Blizzard session to the Hub.
* @param {String} basedir The base path to serve tests from.
* @param {Array} tests An array of string paths of test files.
* @param {Boolean} useProxy True if tests should be fetched over RPC, false otherwise.
*/
function ClientBatch(session, basedir, tests) {
function ClientBatch(session, basedir, tests, useProxy) {
if (!basedir) {
throw new Error("Basedir required.");
}
Expand All @@ -134,7 +141,10 @@ function ClientBatch(session, basedir, tests) {
// Setup our events.
this.once("ack", this.onAck.bind(this));

this.session.emit("rpc.batch", tests, this.emit.bind(this, "ack"));
this.session.emit("rpc.batch", {
tests: tests,
useProxy: useProxy || false
}, this.emit.bind(this, "ack"));
};

util.inherits(ClientBatch, EventEmitter2);
Expand Down
43 changes: 37 additions & 6 deletions lib/hub/batch.js
Expand Up @@ -6,11 +6,23 @@ var EventYoshi = require("eventyoshi");

var TestServer = require("./test-server");

function Batch(manager, id, session, tests) {
/**
* A Batch represents a collection of tests on the Hub.
*
* @class Batch
* @constructor
* @param {BatchManager} manager
* @param {Number} id Batch ID.
* @param {BlizzardSession} session Hub session.
* @param {Array} tests Array of tests.
* @param {Boolean} useProxy True if tests should be fetched over RPC, false otherwise.
*/
function Batch(manager, id, session, tests, useProxy) {
this.manager = manager;
this.id = id;
this.session = session;
this.tests = tests;
this.useProxy = useProxy;
this.agentManager = manager.agentManager;

this.testServer = new TestServer(
Expand Down Expand Up @@ -103,9 +115,13 @@ Batch.prototype.dispatch = function () {
var urls = [],
self = this;

this.tests.forEach(function (test) {
urls.push("/batch/" + self.id + "/test/" + test);
});
if (self.useProxy) {
self.tests.forEach(function (test) {
urls.push("/batch/" + self.id + "/test/" + test);
});
} else {
self.urls = self.tests;
}

agents.forEach(function (agent) {
var id = agent.getId();
Expand Down Expand Up @@ -150,6 +166,13 @@ Batch.prototype.handleFileRequest = function (server, filename) {
});
};

/**
* A BatchManager keeps track of Batch objects on behalf of a Hub.
*
* @class BatchManager
* @constructor
* @param {AgentManager} agentManager AgentManager to use for allocating agents.
*/
function BatchManager(agentManager) {
this.batches = {};
this.agentManager = agentManager;
Expand All @@ -169,10 +192,18 @@ BatchManager.prototype.destroyBatch = function (id) {
delete this.batches[id];
};

BatchManager.prototype.createBatch = function (session, tests, reply) {
/**
* Create a new Batch.
*
* @param {BlizzardSession} session Hub session.
* @param {Array} tests Array of tests.
* @param {Boolean} useProxy True if tests should be fetched over RPC, false otherwise.
* @param {Function} reply Blizzard reply callback.
*/
BatchManager.prototype.createBatch = function (session, tests, useProxy, reply) {
var id = this.newId();

this.batches[id] = new Batch(this, id, session, tests);
this.batches[id] = new Batch(this, id, session, tests, useProxy);

this.batches[id].batchSession.once("end", this.destroyBatch.bind(this, id));

Expand Down
4 changes: 2 additions & 2 deletions lib/hub/index.js
Expand Up @@ -91,8 +91,8 @@ Hub.prototype._setupLogEvents = function (loglevel) {
Hub.prototype._setupAgentManagerEvents = function () {
var self = this;

self.on("batch", function (session, tests, reply) {
self.batchManager.createBatch(session, tests, reply);
self.on("batch", function (session, data, reply) {
self.batchManager.createBatch(session, data.tests, data.useProxy, reply);
});

self.agentManager.on("agentConnect", self.sessions.emit.bind(self.sessions, "rpc.agentConnect"));
Expand Down

0 comments on commit 2ea83d2

Please sign in to comment.