mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
minor cleanup and prevent multiple exit (#39751)
This commit is contained in:
parent
d33cf11556
commit
cc9b614efd
@ -73,6 +73,7 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
WebFs _webFs;
|
||||
DebugConnection _debugConnection;
|
||||
StreamSubscription<vmservice.Event> _stdOutSub;
|
||||
bool _exited = false;
|
||||
|
||||
vmservice.VmService get _vmService => _debugConnection.vmService;
|
||||
|
||||
@ -101,9 +102,13 @@ class ResidentWebRunner extends ResidentRunner {
|
||||
}
|
||||
|
||||
Future<void> _cleanup() async {
|
||||
if (_exited) {
|
||||
return;
|
||||
}
|
||||
await _debugConnection?.close();
|
||||
await _stdOutSub?.cancel();
|
||||
await _webFs?.stop();
|
||||
_exited = true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -155,26 +155,25 @@ class ChromeLauncher {
|
||||
static Future<Chrome> get connectedInstance => _currentCompleter.future;
|
||||
|
||||
/// Returns the full URL of the Chrome remote debugger for the main page.
|
||||
///
|
||||
/// This takes the [base] remote debugger URL (which points to a browser-wide
|
||||
/// page) and uses its JSON API to find the resolved URL for debugging the host
|
||||
/// page.
|
||||
Future<Uri> _getRemoteDebuggerUrl(Uri base) async {
|
||||
try {
|
||||
final HttpClient client = HttpClient();
|
||||
final HttpClientRequest request = await client.getUrl(base.resolve('/json/list'));
|
||||
final HttpClientResponse response = await request.close();
|
||||
final List<dynamic> jsonObject = await json.fuse(utf8).decoder.bind(response).single;
|
||||
return base.resolve(jsonObject.first['devtoolsFrontendUrl']);
|
||||
} catch (_) {
|
||||
// If we fail to talk to the remote debugger protocol, give up and return
|
||||
// the raw URL rather than crashing.
|
||||
return base;
|
||||
///
|
||||
/// This takes the [base] remote debugger URL (which points to a browser-wide
|
||||
/// page) and uses its JSON API to find the resolved URL for debugging the host
|
||||
/// page.
|
||||
Future<Uri> _getRemoteDebuggerUrl(Uri base) async {
|
||||
try {
|
||||
final HttpClient client = HttpClient();
|
||||
final HttpClientRequest request = await client.getUrl(base.resolve('/json/list'));
|
||||
final HttpClientResponse response = await request.close();
|
||||
final List<dynamic> jsonObject = await json.fuse(utf8).decoder.bind(response).single;
|
||||
return base.resolve(jsonObject.first['devtoolsFrontendUrl']);
|
||||
} catch (_) {
|
||||
// If we fail to talk to the remote debugger protocol, give up and return
|
||||
// the raw URL rather than crashing.
|
||||
return base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// A class for managing an instance of Chrome.
|
||||
class Chrome {
|
||||
Chrome._(
|
||||
|
||||
@ -338,6 +338,25 @@ void main() {
|
||||
verify(mockVmService.callServiceExtension('ext.flutter.profileWidgetBuilds',
|
||||
args: <String, Object>{'enabled': true})).called(1);
|
||||
}));
|
||||
|
||||
test('cleanup of resources is safe to call multiple times', () => testbed.run(() async {
|
||||
_setupMocks();
|
||||
bool debugClosed = false;
|
||||
when(mockDebugConnection.close()).thenAnswer((Invocation invocation) async {
|
||||
if (debugClosed) {
|
||||
throw StateError('debug connection closed twice');
|
||||
}
|
||||
debugClosed = true;
|
||||
});
|
||||
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
|
||||
unawaited(residentWebRunner.run(
|
||||
connectionInfoCompleter: connectionInfoCompleter,
|
||||
));
|
||||
await connectionInfoCompleter.future;
|
||||
|
||||
await residentWebRunner.exit();
|
||||
await residentWebRunner.exit();
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user