Skip to content

Commit

Permalink
add --command-timeout server arg
Browse files Browse the repository at this point in the history
so the server can set its own default timeout.
also, clean up some of the command timeout logic
  • Loading branch information
jlipps committed Mar 7, 2014
1 parent a06e4d6 commit e7a72e5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
8 changes: 5 additions & 3 deletions docs/server-args.md
Expand Up @@ -15,7 +15,8 @@ All flags are optional, but some are required in conjunction with certain others
|`-U`, `--udid`|null|Unique device identifier of the connected physical device|`--udid 1adsf-sdfas-asdf-123sdf`|
|`-a`, `--address`|0.0.0.0|IP Address to listen on|`--address 0.0.0.0`|
|`-p`, `--port`|4723|port to listen on|`--port 4723`|
|`-dp`, `--device-port`|4724|(Android-only) port to connect to device on|`--device-port 4724`|
|`-dp`, `--device-port`|4724|[DEPRECATED] (Android-only) port to use on device to talk to Appium. Use --bootstrap-port instead|`--device-port 4724`|
|`-bp`, `--bootstrap-port`|4724|(Android-only) port to use on device to talk to Appium|`--bootstrap-port 4724`|
|`-k`, `--keep-artifacts`|false|(IOS-only) Keep Instruments trace directories||
|`-r`, `--backend-retries`|3|(iOS-only) How many times to retry launching Instruments before saying it crashed or timed out|`--backend-retries 3`|
|`--session-override`|false|Enables session override (clobbering)||
Expand Down Expand Up @@ -53,9 +54,10 @@ All flags are optional, but some are required in conjunction with certain others
|`--selendroid-port`|8080|Local port used for communication with Selendroid|`--selendroid-port 8080`|
|`--chromedriver-port`|9515|Port upon which ChromeDriver will run|`--chromedriver-port 9515`|
|`--use-keystore`|false|(Android-only) When set the keystore will be used to sign apks.||
|`--keystore-path`|/Users/user/.android/debug.keystore|(Android-only) Path to keystore||
|`--keystore-path`|/Users/jlipps/.android/debug.keystore|(Android-only) Path to keystore||
|`--keystore-password`|android|(Android-only) Password to keystore||
|`--key-alias`|androiddebugkey|(Android-only) Key alias||
|`--key-password`|android|(Android-only) Key password||
|`--show-config`|false|Show info about the appium server configuration and exit||
|`--keep-keychains`|false|(iOS) Whether to keep keychains (Library/Keychains) when appium session is started/finished||
|`--command-timeout`|60|The default command timeout for the server to use for all sessions. Will still be overridden by newCommandTimeout cap||
|`--keep-keychains`|false|(iOS) Whether to keep keychains (Library/Keychains) when reset app between sessions||
32 changes: 14 additions & 18 deletions lib/appium.js
Expand Up @@ -37,9 +37,8 @@ var Appium = function (args) {
this.args.fastReset = this.fastReset;
this.sessionOverride = this.args.sessionOverride;
this.resetting = false;
this.defCommandTimeoutMs = 60 * 1000;
this.defCommandTimeoutMs = this.args.defaultCommandTimeout * 1000;
this.commandTimeoutMs = this.defCommandTimeoutMs;
this.origCommandTimeoutMs = this.commandTimeoutMs;
this.commandTimeout = null;
};

Expand Down Expand Up @@ -203,9 +202,8 @@ Appium.prototype.invoke = function (cb) {
JSON.stringify(sessionIdOverride));
}
if (err) return this.cleanupSession(err, cb);
logger.info("Device launched! Ready for commands (will time out in " +
(this.commandTimeoutMs / 1000) + "secs)");
this.resetTimeout();
logger.info("Device launched! Ready for commands");
this.setCommandTimeout(this.desiredCapabilities.newCommandTimeout);
cb(null, this.device);
}.bind(this);

Expand Down Expand Up @@ -275,17 +273,17 @@ Appium.prototype.resetTimeout = function () {
};

Appium.prototype.setCommandTimeout = function (secs, cb) {
logger.info("Setting command timeout to " + secs + " secs");
this.origCommandTimeoutMs = this.commandTimeoutMs;
if (typeof secs === "undefined") {
secs = this.defCommandTimeoutMs / 1000;
logger.info("Setting command timeout to the default of " + secs + " secs");
} else {
logger.info("Setting command timeout to " + secs + " secs");
}
this.commandTimeoutMs = secs * 1000;
this.resetTimeout();
jwpResponse(null, secs, cb);
};

Appium.prototype.resetCommandTimeout = function (cb) {
this.commandTimeoutMs = this.origCommandTimeoutMs;
this.resetTimeout();
jwpResponse(cb);
if (typeof cb === "function") {
jwpResponse(null, secs, cb);
}
};

Appium.prototype.getCommandTimeout = function (cb) {
Expand Down Expand Up @@ -322,7 +320,7 @@ Appium.prototype.reset = function (cb) {
} else if (!this.args.fastReset) {
logger.info("Running generic full reset");
var oldImpWait = this.device.implicitWaitMs
, oldCommandTimeout = this.commandTimeoutMs
, oldCommandTimeoutMs = this.commandTimeoutMs
, oldId = this.sessionId;

this.resetting = true;
Expand All @@ -333,9 +331,7 @@ Appium.prototype.reset = function (cb) {
this.resetting = false;
this.device.implicitWaitMs = oldImpWait;
this.sessionId = oldId;
this.setCommandTimeout(oldCommandTimeout / 1000, function () {
jwpResponse(cb);
});
this.setCommandTimeout(oldCommandTimeoutMs / 1000, cb);
}.bind(this));
}.bind(this));
} else {
Expand Down
13 changes: 2 additions & 11 deletions lib/server/controller.js
Expand Up @@ -131,18 +131,9 @@ exports.createSession = function (req, res) {
req.body = JSON.parse(req.body);
}

var desired = req.body.desiredCapabilities;

var next = function (reqHost, sessionId) {
var redirect = function () {
res.set('Location', "http://" + reqHost + "/wd/hub/session/" + sessionId);
res.send(303);
};
if (desired && _.has(desired, 'newCommandTimeout')) {
req.appium.setCommandTimeout(desired.newCommandTimeout, redirect);
} else {
redirect();
}
res.set('Location', "http://" + reqHost + "/wd/hub/session/" + sessionId);
res.send(303);
};
if (req.appium.preLaunched && req.appium.sessionId) {
req.appium.preLaunched = false;
Expand Down
9 changes: 9 additions & 0 deletions lib/server/parser.js
Expand Up @@ -431,6 +431,15 @@ var args = [
, help: 'Show info about the appium server configuration and exit'
}],

[['--command-timeout'], {
defaultValue: 60
, dest: 'defaultCommandTimeout'
, action: 'store'
, required: false
, help: 'The default command timeout for the server to use for all ' +
'sessions. Will still be overridden by newCommandTimeout cap'
}],

[['--keep-keychains'], {
defaultValue: false
, dest: 'keepKeyChains'
Expand Down

0 comments on commit e7a72e5

Please sign in to comment.