From 3bc5bc00265b792236fa7510b3de903cd4059d43 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 26 Feb 2024 16:31:27 -0800 Subject: [PATCH 1/3] Respect SIGINT (Ctrl-C) for Android scenario_app. --- .../scenario_app/bin/run_android_tests.dart | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/testing/scenario_app/bin/run_android_tests.dart b/testing/scenario_app/bin/run_android_tests.dart index 6a6ed8e9bb659..02ab4a5ec396d 100644 --- a/testing/scenario_app/bin/run_android_tests.dart +++ b/testing/scenario_app/bin/run_android_tests.dart @@ -59,8 +59,14 @@ void main(List args) async { return; } + // Capture CTRL-C. + late final StreamSubscription onSigint; runZonedGuarded( () async { + onSigint = ProcessSignal.sigint.watch().listen((_) { + onSigint.cancel(); + panic(['Received SIGINT']); + }); await _run( verbose: options.verbose, outDir: Directory(options.outDir), @@ -73,9 +79,11 @@ void main(List args) async { contentsGolden: options.outputContentsGolden, ndkStack: options.ndkStack, ); - exit(0); + onSigint.cancel(); + exitCode = 0; }, (Object error, StackTrace stackTrace) { + onSigint.cancel(); if (error is! Panic) { stderr.writeln('Unhandled error: $error'); stderr.writeln(stackTrace); @@ -146,7 +154,7 @@ Future _run({ // for the screenshots. // On LUCI, the host uploads the screenshots to Skia Gold. SkiaGoldClient? skiaGoldClient; - late ServerSocket server; + late final ServerSocket server; final List> pendingComparisons = >[]; await step('Starting server...', () async { server = await ServerSocket.bind(InternetAddress.anyIPv4, _tcpPort); @@ -157,8 +165,7 @@ Future _run({ if (verbose) { stdout.writeln('client connected ${client.remoteAddress.address}:${client.remotePort}'); } - client.transform(const ScreenshotBlobTransformer()).listen( - (Screenshot screenshot) { + client.transform(const ScreenshotBlobTransformer()).listen((Screenshot screenshot) { final String fileName = screenshot.filename; final Uint8List fileContent = screenshot.fileContent; if (verbose) { @@ -182,9 +189,7 @@ Future _run({ }); pendingComparisons.add(comparison); } - }, onError: (dynamic err) { - panic(['error while receiving bytes: $err']); - }, cancelOnError: true); + }); }); }); @@ -336,6 +341,13 @@ Future _run({ } finally { await server.close(); + await step('Killing test app and test runner...', () async { + final int exitCode = await pm.runAndForward([adb.path, 'shell', 'am', 'force-stop', 'dev.flutter.scenarios']); + if (exitCode != 0) { + panic(['could not kill test app']); + } + }); + await step('Killing logcat process...', () async { final bool delivered = logcatProcess.kill(ProcessSignal.sigkill); assert(delivered); From 8ce2fd44758f809d7de06a609dcedfefa56ffa3e Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 26 Feb 2024 17:08:15 -0800 Subject: [PATCH 2/3] Close client connections. --- testing/scenario_app/bin/run_android_tests.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/scenario_app/bin/run_android_tests.dart b/testing/scenario_app/bin/run_android_tests.dart index 02ab4a5ec396d..a139084d55ad1 100644 --- a/testing/scenario_app/bin/run_android_tests.dart +++ b/testing/scenario_app/bin/run_android_tests.dart @@ -156,6 +156,7 @@ Future _run({ SkiaGoldClient? skiaGoldClient; late final ServerSocket server; final List> pendingComparisons = >[]; + final List pendingConnections = []; await step('Starting server...', () async { server = await ServerSocket.bind(InternetAddress.anyIPv4, _tcpPort); if (verbose) { @@ -165,6 +166,7 @@ Future _run({ if (verbose) { stdout.writeln('client connected ${client.remoteAddress.address}:${client.remotePort}'); } + pendingConnections.add(client); client.transform(const ScreenshotBlobTransformer()).listen((Screenshot screenshot) { final String fileName = screenshot.filename; final Uint8List fileContent = screenshot.fileContent; @@ -189,6 +191,8 @@ Future _run({ }); pendingComparisons.add(comparison); } + }, onDone: () { + pendingConnections.remove(client); }); }); }); @@ -340,6 +344,9 @@ Future _run({ }); } finally { await server.close(); + for (final Socket client in pendingConnections.toList()) { + client.close(); + } await step('Killing test app and test runner...', () async { final int exitCode = await pm.runAndForward([adb.path, 'shell', 'am', 'force-stop', 'dev.flutter.scenarios']); From c6afc4daa0ed76b6e4d1913022741f5c5bdedc54 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 26 Feb 2024 18:29:24 -0800 Subject: [PATCH 3/3] ++ --- testing/scenario_app/bin/run_android_tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/scenario_app/bin/run_android_tests.dart b/testing/scenario_app/bin/run_android_tests.dart index a139084d55ad1..8da7892f48f36 100644 --- a/testing/scenario_app/bin/run_android_tests.dart +++ b/testing/scenario_app/bin/run_android_tests.dart @@ -80,7 +80,7 @@ void main(List args) async { ndkStack: options.ndkStack, ); onSigint.cancel(); - exitCode = 0; + exit(0); }, (Object error, StackTrace stackTrace) { onSigint.cancel();