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