[flutter_tools] update coverage collector to use vmservice api (#54682)
This commit is contained in:
parent
14cceefe2b
commit
723bc76847
@ -5,6 +5,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:coverage/coverage.dart' as coverage;
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
@ -201,7 +202,13 @@ Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(St
|
||||
final List<Map<String, dynamic>> coverage = <Map<String, dynamic>>[];
|
||||
for (final Isolate isolateRef in service.vm.isolates) {
|
||||
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 Map<String, Map<String, dynamic>> scripts = <String, Map<String, dynamic>>{};
|
||||
@ -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
|
||||
// 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>>()) {
|
||||
if (!libraryPredicate(script['uri'] as String)) {
|
||||
continue;
|
||||
|
@ -492,6 +492,11 @@ class VMService implements vm_service.VmService {
|
||||
_getEventController(streamId).add(event);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<vm_service.ScriptList> getScripts(String isolateId) {
|
||||
return _delegateService.getScripts(isolateId);
|
||||
}
|
||||
|
||||
/// Reloads the VM.
|
||||
Future<void> getVMOld() async => await vm.reload();
|
||||
|
||||
|
@ -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/vmservice.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
|
||||
import '../src/common.dart';
|
||||
|
||||
@ -19,10 +20,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('Coverage collector Can handle coverage sentinenl data', () async {
|
||||
when(mockVMService.vm.isolates.first.invokeRpcRaw('getScripts', params: anyNamed('params')))
|
||||
.thenAnswer((Invocation invocation) async {
|
||||
return <String, Object>{'type': 'Sentinel', 'kind': 'Collected', 'valueAsString': '<collected>'};
|
||||
});
|
||||
when(mockVMService.getScripts(any))
|
||||
.thenThrow(vm_service.SentinelException.parse('getScripts', <String, Object>{}));
|
||||
final Map<String, Object> result = await collect(null, (String predicate) => true, connector: (Uri uri) async {
|
||||
return mockVMService;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user