Unverified Commit d2947571 authored by Martin Kustermann's avatar Martin Kustermann Committed by GitHub

Ensure to close connection to VM after collecting coverage (#50943)

parent 11589ca2
......@@ -181,7 +181,10 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool Function(String) libra
}) async {
final VMService vmService = await connector(serviceUri);
await vmService.getVM();
return _getAllCoverage(vmService, libraryPredicate);
final Map<String, dynamic> result = await _getAllCoverage(
vmService, libraryPredicate);
await vmService.close();
return result;
}
Future<Map<String, dynamic>> _getAllCoverage(VMService service, bool Function(String) libraryPredicate) async {
......
......@@ -452,6 +452,8 @@ class VMService {
Future<void> getVM() async => await vm.reload();
Future<void> refreshViews({ bool waitForViews = false }) => vm.refreshViews(waitForViews: waitForViews);
Future<void> close() async => await _peer.close();
}
/// An error that is thrown when constructing/updating a service object.
......
......@@ -33,13 +33,11 @@ class MockPeer implements rpc.Peer {
}
@override
bool get isClosed {
throw 'unexpected call to isClosed';
}
bool get isClosed => _isClosed;
@override
Future<dynamic> close() async {
throw 'unexpected call to close()';
_isClosed = true;
}
@override
......@@ -70,6 +68,7 @@ class MockPeer implements rpc.Peer {
List<String> registeredMethods = <String>[];
bool isolatesEnabled = false;
bool _isClosed = false;
Future<void> _getVMLatch;
Completer<void> _currentGetVMLatchCompleter;
......@@ -213,6 +212,14 @@ void main() {
WebSocketConnector: () => (String url, {CompressionOptions compression}) async => throw const SocketException('test'),
});
testUsingContext('closing VMService closes Peer', () async {
final MockPeer mockPeer = MockPeer();
final VMService vmService = VMService(mockPeer, null, null, null, null, null, MockDevice(), null);
expect(mockPeer.isClosed, equals(false));
await vmService.close();
expect(mockPeer.isClosed, equals(true));
});
testUsingContext('refreshViews', () {
FakeAsync().run((FakeAsync time) {
bool done = false;
......
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