Skip to content
50 changes: 39 additions & 11 deletions devices/ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
func (d IOSDevice) Reboot() error {
log.SetLevel(log.WarnLevel)

// ensure tunnel is running for iOS 17+
err := d.startTunnel()
if err != nil {
return fmt.Errorf("failed to start tunnel: %w", err)
}

device, err := d.getEnhancedDevice()
if err != nil {
return fmt.Errorf("failed to get enhanced device connection: %w", err)
Expand Down Expand Up @@ -219,22 +225,20 @@
return nil
}

tunnels, err := d.ListTunnels()
// start tunnel if not already running
// TunnelManager.StartTunnel() will return error if already running
err := d.tunnelManager.StartTunnel()
if err != nil {
return fmt.Errorf("failed to list tunnels: %w", err)
}

if len(tunnels) > 0 {
utils.Verbose("Tunnels available for this device: %v", tunnels)
return nil
}
// check if it's the "already running" error, which is fine

utils.Verbose("No tunnels found, starting a new tunnel")
err = d.tunnelManager.StartTunnel()
if err != nil {
if errors.Is(err, ErrTunnelAlreadyRunning) {

Check failure on line 234 in devices/ios.go

View workflow job for this annotation

GitHub Actions / security

undefined: ErrTunnelAlreadyRunning

Check failure on line 234 in devices/ios.go

View workflow job for this annotation

GitHub Actions / security

undefined: errors
utils.Verbose("Tunnel already running for this device")
return nil
}
return fmt.Errorf("failed to start tunnel: %w", err)
}

utils.Verbose("Started new tunnel for device %s", d.Udid)
time.Sleep(1 * time.Second)
return nil
}
Expand Down Expand Up @@ -369,6 +373,12 @@

utils.Verbose("Running wda with bundleid: %s, testbundleid: %s, xctestconfig: %s", bundleID, testRunnerBundleID, xctestConfig)

// ensure tunnel is running for iOS 17+
err := d.startTunnel()
if err != nil {
return fmt.Errorf("failed to start tunnel: %w", err)
}

device, err := d.getEnhancedDevice()
if err != nil {
return fmt.Errorf("failed to get enhanced device connection: %w", err)
Expand Down Expand Up @@ -588,6 +598,12 @@
func (d IOSDevice) ListApps() ([]InstalledAppInfo, error) {
log.SetLevel(log.WarnLevel)

// ensure tunnel is running for iOS 17+
err := d.startTunnel()
if err != nil {
return nil, fmt.Errorf("failed to start tunnel: %w", err)
}

device, err := d.getEnhancedDevice()
if err != nil {
return nil, fmt.Errorf("failed to get enhanced device connection: %w", err)
Expand Down Expand Up @@ -677,6 +693,12 @@
func (d IOSDevice) InstallApp(path string) error {
log.SetLevel(log.WarnLevel)

// ensure tunnel is running for iOS 17+
err := d.startTunnel()
if err != nil {
return fmt.Errorf("failed to start tunnel: %w", err)
}

device, err := d.getEnhancedDevice()
if err != nil {
return fmt.Errorf("failed to get enhanced device connection: %w", err)
Expand All @@ -699,6 +721,12 @@
func (d IOSDevice) UninstallApp(packageName string) (*InstalledAppInfo, error) {
log.SetLevel(log.WarnLevel)

// ensure tunnel is running for iOS 17+
err := d.startTunnel()
if err != nil {
return nil, fmt.Errorf("failed to start tunnel: %w", err)
}

device, err := d.getEnhancedDevice()
if err != nil {
return nil, fmt.Errorf("failed to get enhanced device connection: %w", err)
Expand Down
6 changes: 4 additions & 2 deletions devices/ios/tunnel-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
log "github.com/sirupsen/logrus"
)

var ErrTunnelAlreadyRunning = errors.New("tunnel is already running")

Check failure on line 16 in devices/ios/tunnel-manager.go

View workflow job for this annotation

GitHub Actions / security

undefined: errors

Check failure on line 16 in devices/ios/tunnel-manager.go

View workflow job for this annotation

GitHub Actions / lint

undefined: errors (typecheck)

Check failure on line 16 in devices/ios/tunnel-manager.go

View workflow job for this annotation

GitHub Actions / test

undefined: errors

type TunnelManager struct {
udid string
tunnelMgr *tunnel.TunnelManager
Expand All @@ -32,7 +34,7 @@
if err := os.MkdirAll(dir, 0o700); err != nil {
return nil, fmt.Errorf("failed to create pair records directory: %w", err)
}

pm, err := tunnel.NewPairRecordManager(dir)
if err != nil {
return nil, fmt.Errorf("failed to create pair record manager: %w", err)
Expand All @@ -56,7 +58,7 @@
defer tm.tunnelMutex.Unlock()

if tm.updateCtx != nil {
return fmt.Errorf("tunnel is already running")
return ErrTunnelAlreadyRunning
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down
Loading