[frdp] Adds DartVM events/driver support. (#17170)
This change adds Dart VM event support (listening for when a VM starts/stops by using a periodic heartbeat). This also adds support to connect to a specific `IsolateRef` through the flutter driver, so that when an application spawns, it can immediately be driven (as shown in included example code).
This commit is contained in:
@@ -62,6 +62,9 @@ const List<TimelineStream> _defaultStreams = const <TimelineStream>[TimelineStre
|
||||
/// Default timeout for short-running RPCs.
|
||||
const Duration _kShortTimeout = const Duration(seconds: 5);
|
||||
|
||||
/// Default timeout for awaiting an Isolate to become runnable.
|
||||
const Duration _kIsolateLoadRunnableTimeout = const Duration(minutes: 1);
|
||||
|
||||
/// Default timeout for long-running RPCs.
|
||||
final Duration _kLongTimeout = _kShortTimeout * 6;
|
||||
|
||||
@@ -146,34 +149,46 @@ class FlutterDriver {
|
||||
/// [logCommunicationToFile] determines whether the command communication
|
||||
/// between the test and the app should be logged to `flutter_driver_commands.log`.
|
||||
///
|
||||
/// [isolateNumber] (optional) determines the specific isolate to connect to.
|
||||
/// If this is left as `null`, will connect to the first isolate found
|
||||
/// running on [dartVmServiceUrl].
|
||||
///
|
||||
/// [isolateReadyTimeout] determines how long after we connect to the VM
|
||||
/// service we will wait for the first isolate to become runnable.
|
||||
static Future<FlutterDriver> connect({
|
||||
String dartVmServiceUrl,
|
||||
bool printCommunication: false,
|
||||
bool logCommunicationToFile: true,
|
||||
Duration isolateReadyTimeout: const Duration(minutes: 1),
|
||||
int isolateNumber,
|
||||
Duration isolateReadyTimeout: _kIsolateLoadRunnableTimeout,
|
||||
}) async {
|
||||
dartVmServiceUrl ??= Platform.environment['VM_SERVICE_URL'];
|
||||
|
||||
if (dartVmServiceUrl == null) {
|
||||
throw new DriverError(
|
||||
'Could not determine URL to connect to application.\n'
|
||||
'Either the VM_SERVICE_URL environment variable should be set, or an explicit\n'
|
||||
'URL should be provided to the FlutterDriver.connect() method.'
|
||||
);
|
||||
'Could not determine URL to connect to application.\n'
|
||||
'Either the VM_SERVICE_URL environment variable should be set, or an explicit\n'
|
||||
'URL should be provided to the FlutterDriver.connect() method.');
|
||||
}
|
||||
|
||||
// Connect to Dart VM services
|
||||
_log.info('Connecting to Flutter application at $dartVmServiceUrl');
|
||||
final VMServiceClientConnection connection = await vmServiceConnectFunction(dartVmServiceUrl);
|
||||
final VMServiceClientConnection connection =
|
||||
await vmServiceConnectFunction(dartVmServiceUrl);
|
||||
final VMServiceClient client = connection.client;
|
||||
final VM vm = await client.getVM();
|
||||
_log.trace('Looking for the isolate');
|
||||
VMIsolate isolate = await vm.isolates.first.loadRunnable()
|
||||
final VMIsolateRef isolateRef = isolateNumber ==
|
||||
null ? vm.isolates.first :
|
||||
vm.isolates.firstWhere(
|
||||
(VMIsolateRef isolate) => isolate.number == isolateNumber);
|
||||
_log.trace('Isolate found with number: ${isolateRef.number}');
|
||||
|
||||
VMIsolate isolate = await isolateRef
|
||||
.loadRunnable()
|
||||
.timeout(isolateReadyTimeout, onTimeout: () {
|
||||
throw new TimeoutException('Timeout while waiting for the isolate to become runnable');
|
||||
});
|
||||
throw new TimeoutException(
|
||||
'Timeout while waiting for the isolate to become runnable');
|
||||
});
|
||||
|
||||
// TODO(yjbanov): vm_service_client does not support "None" pause event yet.
|
||||
// It is currently reported as null, but we cannot rely on it because
|
||||
@@ -189,7 +204,7 @@ class FlutterDriver {
|
||||
isolate.pauseEvent is! VMPauseInterruptedEvent &&
|
||||
isolate.pauseEvent is! VMResumeEvent) {
|
||||
await new Future<Null>.delayed(_kShortTimeout ~/ 10);
|
||||
isolate = await vm.isolates.first.loadRunnable();
|
||||
isolate = await isolateRef.loadRunnable();
|
||||
}
|
||||
|
||||
final FlutterDriver driver = new FlutterDriver.connectedTo(
|
||||
@@ -319,7 +334,7 @@ class FlutterDriver {
|
||||
/// JSON-RPC client useful for sending raw JSON requests.
|
||||
final rpc.Peer _peer;
|
||||
/// The main isolate hosting the Flutter application
|
||||
final VMIsolateRef _appIsolate;
|
||||
final VMIsolate _appIsolate;
|
||||
/// Whether to print communication between host and app to `stdout`.
|
||||
final bool _printCommunication;
|
||||
/// Whether to log communication between host and app to `flutter_driver_commands.log`.
|
||||
|
||||
Reference in New Issue
Block a user