mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Ensure to close connection to VM after collecting coverage (#50943)
This commit is contained in:
parent
11589ca20d
commit
d2947571bd
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user