Unverified Commit 27bdb110 authored by Mehmet Fidanboylu's avatar Mehmet Fidanboylu Committed by GitHub

Expose service client and app isolate in driver (#33431)

parent 0c517aec
...@@ -122,12 +122,12 @@ typedef EvaluatorFunction = dynamic Function(); ...@@ -122,12 +122,12 @@ typedef EvaluatorFunction = dynamic Function();
/// Drives a Flutter Application running in another process. /// Drives a Flutter Application running in another process.
class FlutterDriver { class FlutterDriver {
/// Creates a driver that uses a connection provided by the given /// Creates a driver that uses a connection provided by the given
/// [_serviceClient], [_peer] and [_appIsolate]. /// [serviceClient], [_peer] and [appIsolate].
@visibleForTesting @visibleForTesting
FlutterDriver.connectedTo( FlutterDriver.connectedTo(
this._serviceClient, this.serviceClient,
this._peer, this._peer,
this._appIsolate, { this.appIsolate, {
bool printCommunication = false, bool printCommunication = false,
bool logCommunicationToFile = true, bool logCommunicationToFile = true,
}) : _printCommunication = printCommunication, }) : _printCommunication = printCommunication,
...@@ -383,13 +383,22 @@ class FlutterDriver { ...@@ -383,13 +383,22 @@ class FlutterDriver {
final int _driverId; final int _driverId;
/// Client connected to the Dart VM running the Flutter application /// Client connected to the Dart VM running the Flutter application
final VMServiceClient _serviceClient; ///
/// You can use [VMServiceClient] to check VM version, flags and get
/// notified when a new isolate has been instantiated. That could be
/// useful if your application spawns multiple isolates that you
/// would like to instrument.
final VMServiceClient serviceClient;
/// JSON-RPC client useful for sending raw JSON requests. /// JSON-RPC client useful for sending raw JSON requests.
final rpc.Peer _peer; final rpc.Peer _peer;
/// The main isolate hosting the Flutter application /// The main isolate hosting the Flutter application.
final VMIsolate _appIsolate; ///
/// If you used the [registerExtension] API to instrument your application,
/// you can use this [VMIsolate] to call these extension methods via
/// [invokeExtension].
final VMIsolate appIsolate;
/// Whether to print communication between host and app to `stdout`. /// Whether to print communication between host and app to `stdout`.
final bool _printCommunication; final bool _printCommunication;
...@@ -402,7 +411,7 @@ class FlutterDriver { ...@@ -402,7 +411,7 @@ class FlutterDriver {
try { try {
final Map<String, String> serialized = command.serialize(); final Map<String, String> serialized = command.serialize();
_logCommunication('>>> $serialized'); _logCommunication('>>> $serialized');
final Future<Map<String, dynamic>> future = _appIsolate.invokeExtension( final Future<Map<String, dynamic>> future = appIsolate.invokeExtension(
_flutterExtensionMethodName, _flutterExtensionMethodName,
serialized, serialized,
).then<Map<String, dynamic>>((Object value) => value); ).then<Map<String, dynamic>>((Object value) => value);
...@@ -905,7 +914,7 @@ class FlutterDriver { ...@@ -905,7 +914,7 @@ class FlutterDriver {
try { try {
await _peer await _peer
.sendRequest(_collectAllGarbageMethodName, <String, String>{ .sendRequest(_collectAllGarbageMethodName, <String, String>{
'isolateId': 'isolates/${_appIsolate.numberAsString}', 'isolateId': 'isolates/${appIsolate.numberAsString}',
}); });
} catch (error, stackTrace) { } catch (error, stackTrace) {
throw DriverError( throw DriverError(
...@@ -921,7 +930,7 @@ class FlutterDriver { ...@@ -921,7 +930,7 @@ class FlutterDriver {
/// Returns a [Future] that fires once the connection has been closed. /// Returns a [Future] that fires once the connection has been closed.
Future<void> close() async { Future<void> close() async {
// Don't leak vm_service_client-specific objects, if any // Don't leak vm_service_client-specific objects, if any
await _serviceClient.close(); await serviceClient.close();
await _peer.close(); await _peer.close();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment