Skip to content

Commit

Permalink
perf: tune webDriverAgentUrl case by skiping xcodebuild stuff (#691)
Browse files Browse the repository at this point in the history
* perf: tune webDriverAgentUrl case by skiping xcodebuild stuff

* include a small fix

* Update webdriveragent.js
  • Loading branch information
KazuCocoa authored May 6, 2023
1 parent 2f7f702 commit d8f1457
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class WebDriverAgent {

this.prebuildWDA = args.prebuildWDA;

// this.args.webDriverAgentUrl guiarantees the capabilities acually
// gave 'appium:webDriverAgentUrl' but 'this.webDriverAgentUrl'
// could be used for caching WDA with xcodebuild.
this.webDriverAgentUrl = args.webDriverAgentUrl;

this.started = false;
Expand All @@ -64,10 +67,7 @@ class WebDriverAgent {
this.usePreinstalledWDA = args.usePreinstalledWDA;
this.xctestApiClient = null;

// FIXME: maybe 'this.webDriverAgentUrl' also can ignore
// the xcodebuild instance itself.

this.xcodebuild = this.usePreinstalledWDA
this.xcodebuild = this.canSkipXcodebuild
? null
: new XcodeBuild(this.xcodeVersion, this.device, {
platformVersion: this.platformVersion,
Expand Down Expand Up @@ -96,12 +96,22 @@ class WebDriverAgent {
}, this.log);
}

/**
* Return true if the session does not need xcodebuild.
* @returns {boolean} Whether the session needs/has xcodebuild.
*/
get canSkipXcodebuild () {
// Use this.args.webDriverAgentUrl to guarantee
// the capabilities set gave the `appium:webDriverAgentUrl`.
return this.usePreinstalledWDA || this.args.webDriverAgentUrl;
}

/**
*
* @returns {string} Bundle ID for Xctest.
*/
get bundleIdForXctest () {
return `${this.updatedWDABundleId}.xctrunner` || WDA_RUNNER_BUNDLE_ID_FOR_XCTEST;
return this.updatedWDABundleId ? `${this.updatedWDABundleId}.xctrunner` : WDA_RUNNER_BUNDLE_ID_FOR_XCTEST;
}

setWDAPaths (bootstrapPath, agentPath) {
Expand Down Expand Up @@ -266,7 +276,7 @@ class WebDriverAgent {
return;
}

if (this.usePreinstalledWDA) {
if (this.canSkipXcodebuild) {
return;
}
try {
Expand Down Expand Up @@ -451,10 +461,13 @@ class WebDriverAgent {
this.xctestApiClient.stop();
this.xctestApiClient = null;
}
} else {
} else if (!this.args.webDriverAgentUrl) {
this.log.info('Shutting down sub-processes');
await this.xcodebuild.quit();
await this.xcodebuild.reset();
} else {
this.log.debug('Do not stop xcodebuild nor XCTest session ' +
'since the WDA session is managed by outside this driver.');
}

if (this.jwproxy) {
Expand Down Expand Up @@ -496,7 +509,7 @@ class WebDriverAgent {
}

async retrieveDerivedDataPath () {
if (this.usePreinstalledWDA) {
if (this.canSkipXcodebuild) {
return;
}
return await this.xcodebuild.retrieveDerivedDataPath();
Expand Down

0 comments on commit d8f1457

Please sign in to comment.