-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
fix: uninstall installed uia2 servers if they were greater than on-going session #796
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
060a432
fix: uninstall installed uia2 servers if they were greater than on-go…
KazuCocoa 7c30588
extract some condition check and add tests
KazuCocoa 556eb06
add docstring
KazuCocoa 4b11202
tweak the condtion and add docstring
KazuCocoa f20e50d
update comment
KazuCocoa e2eb9b6
update method names
KazuCocoa ee4c99b
apply comment
KazuCocoa e10294c
modify comment
KazuCocoa 723c7c4
modify comment
KazuCocoa cdb08e4
modify tests
KazuCocoa 1508679
tweak tests further
KazuCocoa 8339010
use be.true/false
KazuCocoa 7e72835
tweak
KazuCocoa 7b64858
update type
KazuCocoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,51 @@ class UiAutomator2Server { | |
return resultInfo; | ||
} | ||
|
||
/** | ||
* @typedef {Object} PackageInfo | ||
* @property {string} installState | ||
* @property {string} appPath | ||
* @property {string} appId | ||
*/ | ||
|
||
/** | ||
* Checks if server components must be installed from the device under test | ||
* in scope of the current driver session. | ||
* | ||
* For example, if one of servers on the device under test was newer than servers current UIA2 driver wants to | ||
* use for the session, the UIA2 driver should uninstall the installed ones in order to avoid | ||
* version mismatch between the UIA2 drier and servers on the device under test. | ||
* Also, if the device under test has missing servers, current UIA2 driver should uninstall all | ||
* servers once in order to install proper servers freshly. | ||
* | ||
* @param {PackageInfo[]} packagesInfo | ||
* @returns {boolean} true if any of components is already installed and the other is not installed | ||
* or the installed one has a newer version. | ||
*/ | ||
shouldUninstallServerPackages(packagesInfo = []) { | ||
const isAnyComponentInstalled = packagesInfo.some( | ||
({installState}) => installState !== this.adb.APP_INSTALL_STATE.NOT_INSTALLED); | ||
const isAnyComponentNotInstalledOrNewer = packagesInfo.some(({installState}) => [ | ||
/** @type {string} */ (this.adb.APP_INSTALL_STATE.NOT_INSTALLED), | ||
/** @type {string} */ (this.adb.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED), | ||
].includes(installState)); | ||
return isAnyComponentInstalled && isAnyComponentNotInstalledOrNewer; | ||
} | ||
|
||
/** | ||
* Checks if server components should be installed on the device under test in scope of the current driver session. | ||
* | ||
* @param {PackageInfo[]} packagesInfo | ||
* @returns {boolean} true if any of components is not installed or older than currently installed in order to | ||
* install or upgrade the servers on the device under test. | ||
*/ | ||
shouldInstallServerPackages(packagesInfo = []) { | ||
return packagesInfo.some(({installState}) => [ | ||
/** @type {string} */ (this.adb.APP_INSTALL_STATE.NOT_INSTALLED), | ||
/** @type {string} */ (this.adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED), | ||
].includes(installState)); | ||
} | ||
|
||
/** | ||
* Installs the apks on to the device or emulator. | ||
* | ||
|
@@ -116,15 +161,12 @@ class UiAutomator2Server { | |
); | ||
|
||
this.log.debug(`Server packages status: ${JSON.stringify(packagesInfo)}`); | ||
// Enforce server packages reinstall if any of the packages is not installed, while the other is | ||
const shouldUninstallServerPackages = (packagesInfo.some(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED) | ||
&& !packagesInfo.every(({installState}) => installState === this.adb.APP_INSTALL_STATE.NOT_INSTALLED)); | ||
// To ensure if the UIA2 driver should uninstall UI2 server packages from the device | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is now not really needed since we have the method itself properly documented |
||
// to use proper UIA2 server versions current UIA2 server wants to use. | ||
const shouldUninstallServerPackages = this.shouldUninstallServerPackages(packagesInfo); | ||
// Install must always follow uninstall. Also, perform the install if | ||
// any of server packages is not installed or is outdated | ||
const shouldInstallServerPackages = shouldUninstallServerPackages || packagesInfo.some(({installState}) => [ | ||
this.adb.APP_INSTALL_STATE.NOT_INSTALLED, | ||
this.adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED, | ||
].includes(installState)); | ||
const shouldInstallServerPackages = shouldUninstallServerPackages || this.shouldInstallServerPackages(packagesInfo); | ||
this.log.info(`Server packages are ${shouldInstallServerPackages ? '' : 'not '}going to be (re)installed`); | ||
if (shouldInstallServerPackages && shouldUninstallServerPackages) { | ||
this.log.info('Full packages reinstall is going to be performed'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe for the installState we can set the type to typeof this.adb.APP_INSTALL_STATE and thus avoid uncessary conversions to string