From 2ea83d27d5ed43bda3642ee32d330023b6781573 Mon Sep 17 00:00:00 2001 From: Reid Burke Date: Sun, 4 Mar 2012 00:06:33 -0800 Subject: [PATCH] Add useProxy option to allow for literal paths. 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. --- lib/client.js | 18 ++++++++++++++---- lib/hub/batch.js | 43 +++++++++++++++++++++++++++++++++++++------ lib/hub/index.js | 4 ++-- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/lib/client.js b/lib/client.js index 1e466298..0f1ca19e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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) { @@ -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); }; /** @@ -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."); } @@ -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); diff --git a/lib/hub/batch.js b/lib/hub/batch.js index 014fee17..33cdfc2b 100644 --- a/lib/hub/batch.js +++ b/lib/hub/batch.js @@ -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( @@ -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(); @@ -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; @@ -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)); diff --git a/lib/hub/index.js b/lib/hub/index.js index d2c80406..1484c31b 100644 --- a/lib/hub/index.js +++ b/lib/hub/index.js @@ -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"));