mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 17:09:33 +08:00
feat: 安卓和iOS安装加锁
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/httprunner/funplugin/myexec"
|
"github.com/httprunner/funplugin/myexec"
|
||||||
@@ -96,6 +97,7 @@ type AndroidDevice struct {
|
|||||||
*gadb.Device
|
*gadb.Device
|
||||||
Options *option.AndroidDeviceOptions
|
Options *option.AndroidDeviceOptions
|
||||||
Logcat *AdbLogcat
|
Logcat *AdbLogcat
|
||||||
|
installMutex sync.Mutex // Mutex to lock installation/uninstallation operations
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) Setup() error {
|
func (dev *AndroidDevice) Setup() error {
|
||||||
@@ -154,6 +156,10 @@ func (dev *AndroidDevice) NewDriver() (driver IDriver, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) Install(apkPath string, opts ...option.InstallOption) error {
|
func (dev *AndroidDevice) Install(apkPath string, opts ...option.InstallOption) error {
|
||||||
|
// Lock the device for installation
|
||||||
|
dev.installMutex.Lock()
|
||||||
|
defer dev.installMutex.Unlock()
|
||||||
|
|
||||||
installOpts := option.NewInstallOptions(opts...)
|
installOpts := option.NewInstallOptions(opts...)
|
||||||
brand, err := dev.Device.Brand()
|
brand, err := dev.Device.Brand()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -261,6 +267,10 @@ func (dev *AndroidDevice) installCommon(apkPath string, args ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *AndroidDevice) Uninstall(packageName string) error {
|
func (dev *AndroidDevice) Uninstall(packageName string) error {
|
||||||
|
// Lock the device for uninstallation
|
||||||
|
dev.installMutex.Lock()
|
||||||
|
defer dev.installMutex.Unlock()
|
||||||
|
|
||||||
_, err := dev.Device.Uninstall(packageName)
|
_, err := dev.Device.Uninstall(packageName)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
@@ -128,6 +129,7 @@ type IOSDevice struct {
|
|||||||
listener *forward.ConnListener
|
listener *forward.ConnListener
|
||||||
localPort int
|
localPort int
|
||||||
}
|
}
|
||||||
|
installMutex sync.Mutex // Mutex to lock installation/uninstallation operations
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceDetail struct {
|
type DeviceDetail struct {
|
||||||
@@ -265,6 +267,10 @@ func (dev *IOSDevice) NewDriver() (driver IDriver, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *IOSDevice) Install(appPath string, opts ...option.InstallOption) (err error) {
|
func (dev *IOSDevice) Install(appPath string, opts ...option.InstallOption) (err error) {
|
||||||
|
// Lock the device for installation
|
||||||
|
dev.installMutex.Lock()
|
||||||
|
defer dev.installMutex.Unlock()
|
||||||
|
|
||||||
installOpts := option.NewInstallOptions(opts...)
|
installOpts := option.NewInstallOptions(opts...)
|
||||||
for i := 0; i <= installOpts.RetryTimes; i++ {
|
for i := 0; i <= installOpts.RetryTimes; i++ {
|
||||||
var conn *zipconduit.Connection
|
var conn *zipconduit.Connection
|
||||||
@@ -284,6 +290,10 @@ func (dev *IOSDevice) Install(appPath string, opts ...option.InstallOption) (err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dev *IOSDevice) Uninstall(bundleId string) error {
|
func (dev *IOSDevice) Uninstall(bundleId string) error {
|
||||||
|
// Lock the device for uninstallation
|
||||||
|
dev.installMutex.Lock()
|
||||||
|
defer dev.installMutex.Unlock()
|
||||||
|
|
||||||
svc, err := installationproxy.New(dev.DeviceEntry)
|
svc, err := installationproxy.New(dev.DeviceEntry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user