Skip to content

Commit

Permalink
clean up and finish for today
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Nov 14, 2022
1 parent 6ad39f1 commit 9edb144
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
26 changes: 18 additions & 8 deletions packages/patrol/lib/patrol_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Future<void> _initCommunication({
runInShell: true,
);
} else if (deviceOs == 'ios') {
// FIXME: no way to do reverse port forwarding on real iOS devices
// final process = await io.Process.start('iproxy',
// [
// ...['--udid', deviceId],
Expand All @@ -104,14 +105,23 @@ Future<void> _initCommunication({
throw StateError('unknown device OS: $deviceOs');
}

await vmService.callServiceExtension(
'ext.flutter.patrol',
isolateId: appIsolateId,
args: <String, String>{
'DRIVER_ISOLATE_ID': developer.Service.getIsolateID(Isolate.current)!,
'DRIVER_VM_SERVICE_WS_URI': serverWsUri.toString(),
},
);
try {
await vmService.callServiceExtension(
'ext.flutter.patrol',
isolateId: appIsolateId,
args: <String, String>{
'DRIVER_ISOLATE_ID': developer.Service.getIsolateID(Isolate.current)!,
'DRIVER_VM_SERVICE_WS_URI': serverWsUri.toString(),
},
);
} on vm.RPCError catch (err) {
print(
'Calling service extension ext.flutter.patrol failed with code ${err.code} and message ${err.message}',
);

print('Exception: ${jsonDecode(err.details!)['exception']}');
io.exit(1);
}

developer.registerExtension(
'ext.leancode.patrol.status',
Expand Down
18 changes: 12 additions & 6 deletions packages/patrol/lib/src/native/binding.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// ignore_for_file: avoid_print

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:vm_service/vm_service.dart' as vm;
import 'package:vm_service/vm_service_io.dart' as vmio;

// ignore: avoid_print
void _defaultPrintLogger(String message) => print('PatrolBinding: $message');

/// Binding that enables some of Patrol's custom functionality, such as tapping
/// on WebViews during a test.
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding {
Expand All @@ -21,13 +22,15 @@ class PatrolBinding extends IntegrationTestWidgetsFlutterBinding {
return _instance!;
}

final _logger = _defaultPrintLogger;

/// ID of the Isolate which the host driver script is running in.
///
/// Has the form of e.g "isolates/1566121372315359".
late String driverIsolateId;

/// Dart Virtual Machine service (aka Dart Observatory server) where
/// Dart VM service (aka Dart Observatory server) running in the main isolate
/// of the Dart VM which is running the test driver script.
late vm.VmService vmService;

// TODO: Remove once https://github.com/flutter/flutter/pull/108430 is
Expand All @@ -49,16 +52,19 @@ class PatrolBinding extends IntegrationTestWidgetsFlutterBinding {
registerServiceExtension(
name: 'patrol',
callback: (args) async {
print('Service extension called with args $args');
_logger('ext.flutter.patrol called');
driverIsolateId = args['DRIVER_ISOLATE_ID']!;
final driverVMServiceWsUri = args['DRIVER_VM_SERVICE_WS_URI']!;
_logger('driver isolate ID: $driverIsolateId');
_logger('driver VM service URI: $driverVMServiceWsUri');

vmService = await vmio.vmServiceConnectUri(driverVMServiceWsUri);

_logger('PatrolBinding: ext.flutter.patrol succeeded');
return <String, String>{'status': 'ok'};
},
);
print('Registered service extension ext.flutter.patrol');
_logger('registered service extension ext.flutter.patrol');
}
}

Expand Down

0 comments on commit 9edb144

Please sign in to comment.