Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to new HTTP API and force use of keepalives in a socket per client #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions lib/soda/client.js
Expand Up @@ -83,8 +83,13 @@ Client.prototype.session = function(fn){
Client.prototype.command = function(cmd, args, fn){
this.emit('command', cmd, args);

// HTTP client
var client = http.createClient(this.port, this.host);
if (!this.agent) {
// Create a dedicated HTTP agent pool for this client, limited to one socket.
// This means all Selenium commands are sent on one socket with keepalives, rather than
// a new socket created for each request, as we never reach the maxSockets default of 5 otherwise.
this.agent = new http.Agent();
this.agent.maxSockets = 1;
}

// Path construction
var path = this.commandPath(cmd, args);
Expand All @@ -96,18 +101,26 @@ Client.prototype.command = function(cmd, args, fn){
// See also: http://jira.openqa.org/browse/SRC-50
if (path.length > 2048 && (this.host + path ).length > 2083) {
postData = this.commandPath(cmd, args).replace('/selenium-server/driver/?', "");
req = client.request('POST'
, path
, { Host: this.host + (this.port ? ':' + this.port : '')
, 'Content-Length': postData.length
req = http.request({
host: this.host,
port: this.port,
method: 'POST',
path: path,
agent: false, // use new socket for each POST
headers: {
'Content-Length': postData.length
, 'Content-Type': 'application/x-www-form-urlencoded'
}
});

req.write(postData);
} else {
req = client.request('GET'
, path
, { Host: this.host + (this.port ? ':' + this.port : '') });
} else {
req = http.request({
host: this.host,
port: this.port,
method: 'GET',
path: path,
agent: this.agent,
});
}

req.on('response', function(res){
Expand Down
3 changes: 2 additions & 1 deletion lib/soda/sauce.js
Expand Up @@ -48,7 +48,8 @@ var SauceClient = exports = module.exports = function SauceClient(options) {
options.browser = options.browser || process.env.SAUCE_BROWSER || 'firefox';
options.username = options.username || process.env.SAUCE_USERNAME;
options['access-key'] = options['access-key'] || process.env.SAUCE_ACCESS_KEY;

options['max-duration'] = options['max-duration'] || 300;

// Allow users to specify an empty browser-version
options['browser-version'] = options['browser-version'] == undefined
? (process.env.SAUCE_BROWSER_VERSION || '')
Expand Down