Skip to content

Commit dfced6d

Browse files
authored
Never panic in finally { ... }, check output logs on success only. (flutter#51814)
Work towards flutter#145988. Should be a NO-OP in behavior, but hopefully make some of the false negatives less confusing (i.e. getting "missing X outputted files when the test is about to fail anyway".
1 parent d33666d commit dfced6d

File tree

2 files changed

+61
-44
lines changed

2 files changed

+61
-44
lines changed

testing/scenario_app/bin/run_android_tests.dart

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,49 @@ Future<void> _run({
392392
panic(<String>['$comparisonsFailed Skia Gold comparisons failed']);
393393
}
394394
});
395+
396+
397+
if (enableImpeller) {
398+
await step('Validating Impeller...', () async {
399+
final _ImpellerBackend expectedImpellerBackend = impellerBackend ?? _ImpellerBackend.vulkan;
400+
if (actualImpellerBackend != expectedImpellerBackend) {
401+
panic(<String>[
402+
'--enable-impeller was specified and expected to find "${expectedImpellerBackend.name}", which did not match "${actualImpellerBackend?.name ?? '<impeller disabled>'}".',
403+
]);
404+
}
405+
});
406+
}
407+
408+
await step('Wait for pending Skia gold comparisons...', () async {
409+
await Future.wait(pendingComparisons);
410+
});
411+
412+
final bool allTestsRun = smokeTestFullPath == null;
413+
final bool checkGoldens = contentsGolden != null;
414+
if (allTestsRun && checkGoldens) {
415+
// Check the output here.
416+
await step('Check output files...', () async {
417+
// TODO(matanlurey): Resolve this in a better way. On CI this file always exists.
418+
File(join(screenshotPath, 'noop.txt')).writeAsStringSync('');
419+
// TODO(gaaclarke): We should move this into dir_contents_diff.
420+
final String diffScreenhotPath = absolute(screenshotPath);
421+
_withTemporaryCwd(absolute(dirname(contentsGolden)), () {
422+
final int exitCode = dirContentsDiff(basename(contentsGolden), diffScreenhotPath);
423+
if (exitCode != 0) {
424+
panic(<String>['Output contents incorrect.']);
425+
}
426+
});
427+
});
428+
}
395429
} finally {
430+
// The finally clause is entered if:
431+
// - The tests have completed successfully.
432+
// - Any step has failed.
433+
//
434+
// Do *NOT* throw exceptions or errors in this block, as these are cleanup
435+
// steps and the program is about to exit. Instead, just log the error and
436+
// continue with the cleanup.
437+
396438
await server.close();
397439
for (final Socket client in pendingConnections.toList()) {
398440
client.close();
@@ -401,7 +443,7 @@ Future<void> _run({
401443
await step('Killing test app and test runner...', () async {
402444
final int exitCode = await pm.runAndForward(<String>[adb.path, 'shell', 'am', 'force-stop', 'dev.flutter.scenarios']);
403445
if (exitCode != 0) {
404-
panic(<String>['could not kill test app']);
446+
logError('could not kill test app');
405447
}
406448
});
407449

@@ -443,17 +485,6 @@ Future<void> _run({
443485
);
444486
});
445487

446-
if (enableImpeller) {
447-
await step('Validating Impeller...', () async {
448-
final _ImpellerBackend expectedImpellerBackend = impellerBackend ?? _ImpellerBackend.vulkan;
449-
if (actualImpellerBackend != expectedImpellerBackend) {
450-
panic(<String>[
451-
'--enable-impeller was specified and expected to find "${expectedImpellerBackend.name}", which did not match "${actualImpellerBackend?.name ?? '<impeller disabled>'}".',
452-
]);
453-
}
454-
});
455-
}
456-
457488
await step('Symbolize stack traces', () async {
458489
final ProcessResult result = await pm.run(
459490
<String>[
@@ -477,47 +508,31 @@ Future<void> _run({
477508
'tcp:3000',
478509
]);
479510
if (exitCode != 0) {
480-
panic(<String>['could not unforward port']);
511+
logError('could not unforward port');
481512
}
482513
});
483514

484515
await step('Uninstalling app APK...', () async {
485-
final int exitCode = await pm.runAndForward(
486-
<String>[adb.path, 'uninstall', 'dev.flutter.scenarios']);
516+
final int exitCode = await pm.runAndForward(<String>[
517+
adb.path,
518+
'uninstall',
519+
'dev.flutter.scenarios',
520+
]);
487521
if (exitCode != 0) {
488-
panic(<String>['could not uninstall app apk']);
522+
logError('could not uninstall app apk');
489523
}
490524
});
491525

492526
await step('Uninstalling test APK...', () async {
493-
final int exitCode = await pm.runAndForward(
494-
<String>[adb.path, 'uninstall', 'dev.flutter.scenarios.test']);
527+
final int exitCode = await pm.runAndForward(<String>[
528+
adb.path,
529+
'uninstall',
530+
'dev.flutter.scenarios.test',
531+
]);
495532
if (exitCode != 0) {
496-
panic(<String>['could not uninstall app apk']);
533+
logError('could not uninstall app apk');
497534
}
498535
});
499-
500-
await step('Wait for Skia gold comparisons...', () async {
501-
await Future.wait(pendingComparisons);
502-
});
503-
504-
final bool allTestsRun = smokeTestFullPath == null;
505-
final bool checkGoldens = contentsGolden != null;
506-
if (allTestsRun && checkGoldens) {
507-
// Check the output here.
508-
await step('Check output files...', () async {
509-
// TODO(matanlurey): Resolve this in a better way. On CI this file always exists.
510-
File(join(screenshotPath, 'noop.txt')).writeAsStringSync('');
511-
// TODO(gaaclarke): We should move this into dir_contents_diff.
512-
final String diffScreenhotPath = absolute(screenshotPath);
513-
_withTemporaryCwd(absolute(dirname(contentsGolden)), () {
514-
final int exitCode = dirContentsDiff(basename(contentsGolden), diffScreenhotPath);
515-
if (exitCode != 0) {
516-
panic(<String>['Output contents incorrect.']);
517-
}
518-
});
519-
});
520-
}
521536
}
522537
}
523538

testing/scenario_app/bin/utils/logs.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ void logWarning(String msg) {
3939
_logWithColor(_yellow, msg);
4040
}
4141

42+
void logError(String msg) {
43+
_logWithColor(_red, msg);
44+
}
45+
4246
final class Panic extends Error {}
4347

4448
Never panic(List<String> messages) {
45-
for (final String message in messages) {
46-
_logWithColor(_red, message);
47-
}
49+
messages.forEach(logError);
4850
throw Panic();
4951
}

0 commit comments

Comments
 (0)