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

fix: uninstall installed uia2 servers if they were greater than on-going session #796

Merged
merged 14 commits into from
Jun 22, 2024

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Jun 21, 2024

appium/appium#19799 (comment)

The current UIA2 driver does not uninstall UIA2 servers on the device if they are newer than newly installed servers by the UIA2. It could cause old UIA2 driver with newer UIA2 servers on the device, which is a mismatch condition. It could cause unexpected behavior.
 
Maybe... this.adb.APP_INSTALL_STATE.NOT_INSTALLED condition should be this.adb.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED to "uninstall" installed UIA2 servers?

It looks like sinon mock's expects, never, once etc might not be so reliable. Some could be not good. To improve condition check as test code, I have extracted condition check into two methods and added tests for them. At least shouldUninstallServerPackages and canInstallServerPackages tests should be reliable.

@KazuCocoa KazuCocoa marked this pull request as ready for review June 21, 2024 06:39
* @param {PackageInfo[]} packagesInfo
* @returns {boolean}
*/
canInstallServerPackages (packagesInfo = []) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's rather shouldInstall

* @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.
*/
shouldInstall(packagesInfo = []) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldInstallServerPackages

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
// to use peoper UIA2 server versions current UIA2 server wants to use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: proper

systemPort: 4724,
host: 'localhost',
devicePort: 6790,
disableWindowAnimation: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need these specific capabilities for unit tests? they are not used anyway

uiautomator2.shouldUninstallServerPackages([
{
'installState': adb.APP_INSTALL_STATE.NOT_INSTALLED,
'appPath': 'path/to/appium-uiautomator2-server.apk',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these items should also be replaced by constants like it was done above

uiautomator2.shouldInstall([
{
'installState': adb.APP_INSTALL_STATE.NOT_INSTALLED,
'appPath': 'path/to/appium-uiautomator2-server.apk',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@@ -97,6 +97,51 @@ class UiAutomator2Server {
return resultInfo;
}

/**
* @typedef {Object} PackageInfo
* @property {string} installState
Copy link
Contributor

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

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

@KazuCocoa KazuCocoa merged commit 62b9056 into master Jun 22, 2024
10 checks passed
@KazuCocoa KazuCocoa deleted the uninstall-newone branch June 22, 2024 04:29
github-actions bot pushed a commit that referenced this pull request Jun 22, 2024
## [3.5.7](v3.5.6...v3.5.7) (2024-06-22)

### Bug Fixes

* uninstall installed uia2 servers if they were greater than on-going session ([#796](#796)) ([62b9056](62b9056))
Copy link

🎉 This PR is included in version 3.5.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants