@@ -59,8 +59,14 @@ void main(List<String> args) async {
5959 return ;
6060 }
6161
62+ // Capture CTRL-C.
63+ late final StreamSubscription <void > onSigint;
6264 runZonedGuarded (
6365 () async {
66+ onSigint = ProcessSignal .sigint.watch ().listen ((_) {
67+ onSigint.cancel ();
68+ panic (< String > ['Received SIGINT' ]);
69+ });
6470 await _run (
6571 verbose: options.verbose,
6672 outDir: Directory (options.outDir),
@@ -73,9 +79,11 @@ void main(List<String> args) async {
7379 contentsGolden: options.outputContentsGolden,
7480 ndkStack: options.ndkStack,
7581 );
76- exit (0 );
82+ onSigint.cancel ();
83+ exitCode = 0 ;
7784 },
7885 (Object error, StackTrace stackTrace) {
86+ onSigint.cancel ();
7987 if (error is ! Panic ) {
8088 stderr.writeln ('Unhandled error: $error ' );
8189 stderr.writeln (stackTrace);
@@ -146,7 +154,7 @@ Future<void> _run({
146154 // for the screenshots.
147155 // On LUCI, the host uploads the screenshots to Skia Gold.
148156 SkiaGoldClient ? skiaGoldClient;
149- late ServerSocket server;
157+ late final ServerSocket server;
150158 final List <Future <void >> pendingComparisons = < Future <void >> [];
151159 await step ('Starting server...' , () async {
152160 server = await ServerSocket .bind (InternetAddress .anyIPv4, _tcpPort);
@@ -157,8 +165,7 @@ Future<void> _run({
157165 if (verbose) {
158166 stdout.writeln ('client connected ${client .remoteAddress .address }:${client .remotePort }' );
159167 }
160- client.transform (const ScreenshotBlobTransformer ()).listen (
161- (Screenshot screenshot) {
168+ client.transform (const ScreenshotBlobTransformer ()).listen ((Screenshot screenshot) {
162169 final String fileName = screenshot.filename;
163170 final Uint8List fileContent = screenshot.fileContent;
164171 if (verbose) {
@@ -182,9 +189,7 @@ Future<void> _run({
182189 });
183190 pendingComparisons.add (comparison);
184191 }
185- }, onError: (dynamic err) {
186- panic (< String > ['error while receiving bytes: $err ' ]);
187- }, cancelOnError: true );
192+ });
188193 });
189194 });
190195
@@ -336,6 +341,13 @@ Future<void> _run({
336341 } finally {
337342 await server.close ();
338343
344+ await step ('Killing test app and test runner...' , () async {
345+ final int exitCode = await pm.runAndForward (< String > [adb.path, 'shell' , 'am' , 'force-stop' , 'dev.flutter.scenarios' ]);
346+ if (exitCode != 0 ) {
347+ panic (< String > ['could not kill test app' ]);
348+ }
349+ });
350+
339351 await step ('Killing logcat process...' , () async {
340352 final bool delivered = logcatProcess.kill (ProcessSignal .sigkill);
341353 assert (delivered);
0 commit comments