Unverified Commit a0b2878e authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Make tool coverage collection resilient to sentinel coverage data (#35186)

parent 24eabe1f
......@@ -184,13 +184,17 @@ class CoverageCollector extends TestWatcher {
}
}
Future<Map<String, dynamic>> collect(Uri serviceUri, bool Function(String) libraryPredicate) async {
final VMService vmService = await VMService.connect(serviceUri, compression: CompressionOptions.compressionOff);
Future<VMService> _defaultConnect(Uri serviceUri) {
return VMService.connect(serviceUri, compression: CompressionOptions.compressionOff);
}
Future<Map<String, dynamic>> collect(Uri serviceUri, bool Function(String) libraryPredicate,
[Future<VMService> Function(Uri) connector = _defaultConnect]) async {
final VMService vmService = await connector(serviceUri);
await vmService.getVM();
return _getAllCoverage(vmService, libraryPredicate);
}
Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(String) libraryPredicate) async {
await service.getVM();
final List<Map<String, dynamic>> coverage = <Map<String, dynamic>>[];
......@@ -203,6 +207,13 @@ Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(St
final Map<String, Map<String, dynamic>> sourceReports = <String, Map<String, dynamic>>{};
// 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 (Map<String, dynamic> script in scriptList['scripts']) {
if (!libraryPredicate(script['uri'])) {
continue;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
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 'src/common.dart';
void main() {
MockVMService mockVMService;
setUp(() {
mockVMService = MockVMService();
});
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>'};
});
final Map<String, Object> result = await collect(null, (String predicate) => true, (Uri uri) async {
return mockVMService;
});
expect(result, <String, Object>{'type': 'CodeCoverage', 'coverage': <Object>[]});
});
}
class MockVMService extends Mock implements VMService {
@override
final MockVM vm = MockVM();
}
class MockVM extends Mock implements VM {
@override
final List<MockIsolate> isolates = <MockIsolate>[ MockIsolate() ];
}
class MockIsolate extends Mock implements Isolate {}
class MockProcess extends Mock implements Process {
final Completer<int>completer = Completer<int>();
@override
Future<int> get exitCode => completer.future;
}
\ No newline at end of file
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