From 22374517111fbe71d14f2ecbff72f4c0698ae0aa Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 24 Oct 2019 07:57:52 -0700 Subject: [PATCH] Don't eagerly call runMain when --start-paused is provided to web application (#42144) --- .../src/build_runner/resident_web_runner.dart | 12 +++++++++- .../resident_web_runner_test.dart | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart index a7d8e87160..5c69b32ae1 100644 --- a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart @@ -259,7 +259,17 @@ class ResidentWebRunner extends ResidentRunner { unawaited(_vmService.registerService('reloadSources', 'FlutterTools')); websocketUri = Uri.parse(_connectionResult.debugConnection.uri); // Always run main after connecting because start paused doesn't work yet. - _connectionResult.appConnection.runMain(); + if (!debuggingOptions.startPaused || !supportsServiceProtocol) { + _connectionResult.appConnection.runMain(); + } else { + StreamSubscription resumeSub; + resumeSub = _connectionResult.debugConnection.vmService.onDebugEvent.listen((vmservice.Event event) { + if (event.type == vmservice.EventKind.kResume) { + _connectionResult.appConnection.runMain(); + resumeSub.cancel(); + } + }); + } } if (websocketUri != null) { printStatus('Debug service listening on $websocketUri'); diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index 1990e7c26b..a08408c4e4 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -83,6 +83,9 @@ void main() { when(mockVmService.onStdoutEvent).thenAnswer((Invocation _) { return const Stream.empty(); }); + when(mockVmService.onDebugEvent).thenAnswer((Invocation _) { + return const Stream.empty(); + }); when(mockDebugConnection.uri).thenReturn('ws://127.0.0.1/abcd/'); } @@ -174,6 +177,27 @@ void main() { expect(bufferLogger.statusText, contains('THIS MESSAGE IS IMPORTANT')); })); + test('Does not run main with --start-paused', () => testbed.run(() async { + residentWebRunner = ResidentWebRunner( + mockWebDevice, + flutterProject: FlutterProject.current(), + debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, startPaused: true), + ipv6: true, + ); + _setupMocks(); + final Completer connectionInfoCompleter = Completer(); + final StreamController controller = StreamController.broadcast(); + when(mockVmService.onStdoutEvent).thenAnswer((Invocation _) { + return controller.stream; + }); + unawaited(residentWebRunner.run( + connectionInfoCompleter: connectionInfoCompleter, + )); + await connectionInfoCompleter.future; + + verifyNever(mockAppConnection.runMain()); + })); + test('Can hot reload after attaching', () => testbed.run(() async { _setupMocks(); final BufferLogger bufferLogger = logger;