Unverified Commit 723bc768 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] update coverage collector to use vmservice api (#54682)

parent 14cceefe
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:coverage/coverage.dart' as coverage; import 'package:coverage/coverage.dart' as coverage;
import 'package:vm_service/vm_service.dart' as vm_service;
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/io.dart'; import '../base/io.dart';
...@@ -201,7 +202,13 @@ Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(St ...@@ -201,7 +202,13 @@ Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(St
final List<Map<String, dynamic>> coverage = <Map<String, dynamic>>[]; final List<Map<String, dynamic>> coverage = <Map<String, dynamic>>[];
for (final Isolate isolateRef in service.vm.isolates) { for (final Isolate isolateRef in service.vm.isolates) {
await isolateRef.load(); await isolateRef.load();
final Map<String, dynamic> scriptList = await isolateRef.invokeRpcRaw('getScripts', params: <String, dynamic>{'isolateId': isolateRef.id}); Map<String, Object> scriptList;
try {
final vm_service.ScriptList actualScriptList = await service.getScripts(isolateRef.id);
scriptList = actualScriptList.json;
} on vm_service.SentinelException {
continue;
}
final List<Future<void>> futures = <Future<void>>[]; final List<Future<void>> futures = <Future<void>>[];
final Map<String, Map<String, dynamic>> scripts = <String, Map<String, dynamic>>{}; final Map<String, Map<String, dynamic>> scripts = <String, Map<String, dynamic>>{};
...@@ -209,12 +216,6 @@ Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(St ...@@ -209,12 +216,6 @@ Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(St
// For each ScriptRef loaded into the VM, load the corresponding Script and // For each ScriptRef loaded into the VM, load the corresponding Script and
// SourceReport object. // SourceReport object.
// We may receive such objects as
// {type: Sentinel, kind: Collected, valueAsString: <collected>}
// that need to be skipped.
if (scriptList['scripts'] == null) {
continue;
}
for (final Map<String, dynamic> script in (scriptList['scripts'] as List<dynamic>).cast<Map<String, dynamic>>()) { for (final Map<String, dynamic> script in (scriptList['scripts'] as List<dynamic>).cast<Map<String, dynamic>>()) {
if (!libraryPredicate(script['uri'] as String)) { if (!libraryPredicate(script['uri'] as String)) {
continue; continue;
......
...@@ -492,6 +492,11 @@ class VMService implements vm_service.VmService { ...@@ -492,6 +492,11 @@ class VMService implements vm_service.VmService {
_getEventController(streamId).add(event); _getEventController(streamId).add(event);
} }
@override
Future<vm_service.ScriptList> getScripts(String isolateId) {
return _delegateService.getScripts(isolateId);
}
/// Reloads the VM. /// Reloads the VM.
Future<void> getVMOld() async => await vm.reload(); Future<void> getVMOld() async => await vm.reload();
......
...@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/base/io.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/test/coverage_collector.dart'; import 'package:flutter_tools/src/test/coverage_collector.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import '../src/common.dart'; import '../src/common.dart';
...@@ -19,10 +20,8 @@ void main() { ...@@ -19,10 +20,8 @@ void main() {
}); });
test('Coverage collector Can handle coverage sentinenl data', () async { test('Coverage collector Can handle coverage sentinenl data', () async {
when(mockVMService.vm.isolates.first.invokeRpcRaw('getScripts', params: anyNamed('params'))) when(mockVMService.getScripts(any))
.thenAnswer((Invocation invocation) async { .thenThrow(vm_service.SentinelException.parse('getScripts', <String, Object>{}));
return <String, Object>{'type': 'Sentinel', 'kind': 'Collected', 'valueAsString': '<collected>'};
});
final Map<String, Object> result = await collect(null, (String predicate) => true, connector: (Uri uri) async { final Map<String, Object> result = await collect(null, (String predicate) => true, connector: (Uri uri) async {
return mockVMService; return mockVMService;
}); });
......
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