Skip to content

Commit

Permalink
Add device ready check (#135526)
Browse files Browse the repository at this point in the history
*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one issue.*
Fixes flutter/flutter#121420

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
  • Loading branch information
ricardoamador authored Sep 30, 2023
1 parent d7739df commit 4e5e47e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
53 changes: 51 additions & 2 deletions dev/devicelab/lib/framework/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:io';
import 'dart:math' as math;

import 'package:path/path.dart' as path;
import 'package:retry/retry.dart';

import 'utils.dart';

Expand Down Expand Up @@ -193,6 +194,20 @@ abstract class Device {
/// Stop a process.
Future<void> stop(String packageName);

/// Wait for the device to become ready.
Future<void> awaitDevice();

Future<void> uninstallApp() async {
await flutter('install', options: <String>[
'--uninstall-only',
'-d',
deviceId]);

await Future<void>.delayed(const Duration(seconds: 2));

await awaitDevice();
}

@override
String toString() {
return 'device: $deviceId';
Expand Down Expand Up @@ -848,6 +863,23 @@ class AndroidDevice extends Device {
Future<void> reboot() {
return adb(<String>['reboot']);
}

@override
Future<void> awaitDevice() async {
print('Waiting for device.');
final String waitOut = await adb(<String>['wait-for-device']);
print(waitOut);
const RetryOptions retryOptions = RetryOptions(delayFactor: Duration(seconds: 1), maxAttempts: 10, maxDelay: Duration(minutes: 1));
await retryOptions.retry(() async {
final String adbShellOut = await adb(<String>['shell', 'getprop sys.boot_completed']);
if (adbShellOut != '1') {
print('Device not ready.');
print(adbShellOut);
throw const DeviceException('Phone not ready.');
}
}, retryIf: (Exception e) => e is DeviceException);
print('Done waiting for device.');
}
}

class IosDeviceDiscovery implements DeviceDiscovery {
Expand Down Expand Up @@ -1081,6 +1113,9 @@ class IosDevice extends Device {
Future<void> reboot() {
return Process.run('idevicediagnostics', <String>['restart', '-u', deviceId]);
}

@override
Future<void> awaitDevice() async {}
}

class LinuxDevice extends Device {
Expand Down Expand Up @@ -1133,6 +1168,9 @@ class LinuxDevice extends Device {

@override
Future<void> wakeUp() async { }

@override
Future<void> awaitDevice() async {}
}

class MacosDevice extends Device {
Expand Down Expand Up @@ -1185,6 +1223,9 @@ class MacosDevice extends Device {

@override
Future<void> wakeUp() async { }

@override
Future<void> awaitDevice() async {}
}

class WindowsDevice extends Device {
Expand Down Expand Up @@ -1237,6 +1278,9 @@ class WindowsDevice extends Device {

@override
Future<void> wakeUp() async { }

@override
Future<void> awaitDevice() async {}
}

/// Fuchsia device.
Expand Down Expand Up @@ -1291,6 +1335,9 @@ class FuchsiaDevice extends Device {
Future<void> reboot() async {
// Unsupported.
}

@override
Future<void> awaitDevice() async {}
}

/// Path to the `adb` executable.
Expand Down Expand Up @@ -1366,6 +1413,9 @@ class FakeDevice extends Device {
Future<void> reboot() async {
// Unsupported.
}

@override
Future<void> awaitDevice() async {}
}

class FakeDeviceDiscovery implements DeviceDiscovery {
Expand Down Expand Up @@ -1428,6 +1478,5 @@ class FakeDeviceDiscovery implements DeviceDiscovery {
}

@override
Future<void> performPreflightTasks() async {
}
Future<void> performPreflightTasks() async { }
}
14 changes: 3 additions & 11 deletions dev/devicelab/lib/tasks/perf_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,7 @@ class StartupTest {
}
}

await flutter('install', options: <String>[
'--uninstall-only',
'-d',
device.deviceId,
]);
await device.uninstallApp();
}

final Map<String, dynamic> averageResults = _average(results, iterations);
Expand Down Expand Up @@ -1084,11 +1080,7 @@ class DevtoolsStartupTest {
await process.exitCode;
}

await flutter('install', options: <String>[
'--uninstall-only',
'-d',
device.deviceId,
]);
await device.uninstallApp();

if (sawLine) {
return TaskResult.success(null, benchmarkScoreKeys: <String>[]);
Expand Down Expand Up @@ -1850,7 +1842,7 @@ class MemoryTest {
}

await adb.cancel();
await flutter('install', options: <String>['--uninstall-only', '-d', device!.deviceId]);
await device!.uninstallApp();

final ListStatistics startMemoryStatistics = ListStatistics(_startMemory);
final ListStatistics endMemoryStatistics = ListStatistics(_endMemory);
Expand Down

0 comments on commit 4e5e47e

Please sign in to comment.