Unverified Commit 39daab29 authored by Andrew Davies's avatar Andrew Davies Committed by GitHub

[frdp] Add optional dart isolate filter. (#22590)

* [frdp] Add optional dart isolate filter.

It's now default to filter out non-flutter isolates when searching
across Dart VM's.  This is due to a possible issue wherein an Isolate
for testing might have the same name as the flutter Isolate.

In addition, logging messages have been added in dart_vm.dart for
debugging.
parent f7e0f836
...@@ -120,16 +120,24 @@ class DartVm { ...@@ -120,16 +120,24 @@ class DartVm {
/// ///
/// This is not limited to Isolates running Flutter, but to any Isolate on the /// This is not limited to Isolates running Flutter, but to any Isolate on the
/// VM. /// VM.
///
/// `includeNonFlutterIsolates` makes sure to add non-flutter Dart isolates,
/// and defaults to `false`.
Future<List<IsolateRef>> getMainIsolatesByPattern( Future<List<IsolateRef>> getMainIsolatesByPattern(
Pattern pattern, { Pattern pattern, {
Duration timeout = _kRpcTimeout, Duration timeout = _kRpcTimeout,
bool includeNonFlutterIsolates = false,
}) async { }) async {
final Map<String, dynamic> jsonVmRef = final Map<String, dynamic> jsonVmRef =
await invokeRpc('getVM', timeout: timeout); await invokeRpc('getVM', timeout: timeout);
final List<IsolateRef> result = <IsolateRef>[]; final List<IsolateRef> result = <IsolateRef>[];
for (Map<String, dynamic> jsonIsolate in jsonVmRef['isolates']) { for (Map<String, dynamic> jsonIsolate in jsonVmRef['isolates']) {
final String name = jsonIsolate['name']; final String name = jsonIsolate['name'];
if (name.contains(pattern)) { // `:main()` is included at the end of a flutter isolate, whereas the
// name of a dart Isolate is concluded as if the name were a function.
if (name.contains(pattern) &&
(includeNonFlutterIsolates || name.contains(RegExp(r':main\(\)')))) {
_log.fine('Found Isolate matching "$pattern": "$name"');
result.add(IsolateRef._fromJson(jsonIsolate, this)); result.add(IsolateRef._fromJson(jsonIsolate, this));
} }
} }
......
...@@ -85,9 +85,8 @@ void main() { ...@@ -85,9 +85,8 @@ void main() {
}; };
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) { Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(any, any)) when(mockPeer.sendRequest(any, any)).thenAnswer((_) =>
.thenAnswer((_) => Future<Map<String, dynamic>>( Future<Map<String, dynamic>>(() => flutterViewCannedResponses));
() => flutterViewCannedResponses));
return Future<json_rpc.Peer>(() => mockPeer); return Future<json_rpc.Peer>(() => mockPeer);
} }
...@@ -141,9 +140,8 @@ void main() { ...@@ -141,9 +140,8 @@ void main() {
}; };
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) { Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(any, any)) when(mockPeer.sendRequest(any, any)).thenAnswer((_) =>
.thenAnswer((_) => Future<Map<String, dynamic>>( Future<Map<String, dynamic>>(() => flutterViewCannedResponses));
() => flutterViewCannedResponses));
return Future<json_rpc.Peer>(() => mockPeer); return Future<json_rpc.Peer>(() => mockPeer);
} }
...@@ -189,8 +187,8 @@ void main() { ...@@ -189,8 +187,8 @@ void main() {
}; };
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) { Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(any, any)) when(mockPeer.sendRequest(any, any)).thenAnswer((_) =>
.thenAnswer((_) => Future<Map<String, dynamic>>( Future<Map<String, dynamic>>(
() => flutterViewCannedResponseMissingId)); () => flutterViewCannedResponseMissingId));
return Future<json_rpc.Peer>(() => mockPeer); return Future<json_rpc.Peer>(() => mockPeer);
} }
...@@ -220,24 +218,30 @@ void main() { ...@@ -220,24 +218,30 @@ void main() {
<String, dynamic>{ <String, dynamic>{
'type': '@Isolate', 'type': '@Isolate',
'fixedId': 'true', 'fixedId': 'true',
'id': 'isolates/1', 'id': 'isolates/2',
'name': 'file://flutterBinary1:main()', 'name': '0:dart_name_pattern()',
'number': '2', 'number': '2',
}, },
<String, dynamic>{ <String, dynamic>{
'type': '@Isolate', 'type': '@Isolate',
'fixedId': 'true', 'fixedId': 'true',
'id': 'isolates/2', 'id': 'isolates/3',
'name': 'file://flutterBinary2:main()', 'name': 'file://flutterBinary2:main()',
'number': '3', 'number': '3',
}, },
<String, dynamic>{
'type': '@Isolate',
'fixedId': 'true',
'id': 'isolates/4',
'name': '0:some_other_dart_name_pattern()',
'number': '4',
},
], ],
}; };
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) { Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(any, any)) when(mockPeer.sendRequest(any, any)).thenAnswer(
.thenAnswer((_) => (_) => Future<Map<String, dynamic>>(() => vmCannedResponse));
Future<Map<String, dynamic>>(() => vmCannedResponse));
return Future<json_rpc.Peer>(() => mockPeer); return Future<json_rpc.Peer>(() => mockPeer);
} }
...@@ -245,9 +249,15 @@ void main() { ...@@ -245,9 +249,15 @@ void main() {
final DartVm vm = final DartVm vm =
await DartVm.connect(Uri.parse('http://whatever.com/ws')); await DartVm.connect(Uri.parse('http://whatever.com/ws'));
expect(vm, isNot(null)); expect(vm, isNot(null));
final List<IsolateRef> isolates = final List<IsolateRef> matchingFlutterIsolates =
await vm.getMainIsolatesByPattern('flutterBinary'); await vm.getMainIsolatesByPattern('flutterBinary');
expect(isolates.length, 2); expect(matchingFlutterIsolates.length, 1);
final List<IsolateRef> allFlutterIsolates =
await vm.getMainIsolatesByPattern('');
expect(allFlutterIsolates.length, 2);
final List<IsolateRef> allIsolates = await vm.getMainIsolatesByPattern('',
includeNonFlutterIsolates: true);
expect(allIsolates.length, 4);
}); });
test('invalid flutter view missing ID', () async { test('invalid flutter view missing ID', () async {
...@@ -269,8 +279,8 @@ void main() { ...@@ -269,8 +279,8 @@ void main() {
}; };
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) { Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(any, any)) when(mockPeer.sendRequest(any, any)).thenAnswer((_) =>
.thenAnswer((_) => Future<Map<String, dynamic>>( Future<Map<String, dynamic>>(
() => flutterViewCannedResponseMissingIsolateName)); () => flutterViewCannedResponseMissingIsolateName));
return Future<json_rpc.Peer>(() => mockPeer); return Future<json_rpc.Peer>(() => mockPeer);
} }
......
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