[ci] Take screenshot when native drive test is taking longer than 10 minutes (#8050)

If the `flutter test` run takes more than 10 minutes (default timeout is 12 minutes) take a screenshot and attach to the logs directory.

Helped debug https://github.com/flutter/flutter/issues/153578#issuecomment-2465941063.

Probably `flutter test` should have a screenshot option similar to `flutter drive`, but at the moment it doesn't.
This commit is contained in:
Jenn Magder
2024-11-18 15:37:04 -08:00
committed by GitHub
parent afb1aff771
commit fc4adc78aa
3 changed files with 124 additions and 7 deletions

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
@ -439,17 +440,36 @@ class DriveExamplesCommand extends PackageLoopingCommand {
bool passed = true;
for (final String target in individualRunTargets) {
final int exitCode = await processRunner.runAndStream(
final Timer timeoutTimer = Timer(const Duration(minutes: 10), () async {
final String screenshotBasename =
'test-timeout-screenshot_${target.replaceAll(platform.pathSeparator, '_')}.png';
printWarning(
'Test is taking a long time, taking screenshot $screenshotBasename...');
await processRunner.runAndStream(
flutterCommand,
<String>[
'test',
'screenshot',
...deviceFlags,
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
if (logsDirectory != null) '--debug-logs-dir=${logsDirectory.path}',
target,
if (logsDirectory != null)
'--out=${logsDirectory.childFile(screenshotBasename).path}',
],
workingDir: example.directory);
workingDir: example.directory,
);
});
final int exitCode = await processRunner.runAndStream(
flutterCommand,
<String>[
'test',
...deviceFlags,
if (enableExperiment.isNotEmpty)
'--enable-experiment=$enableExperiment',
if (logsDirectory != null) '--debug-logs-dir=${logsDirectory.path}',
target,
],
workingDir: example.directory,
);
timeoutTimer.cancel();
passed = passed && (exitCode == 0);
}
return passed;