mirror of
https://github.com/flutter/packages.git
synced 2025-08-24 11:39:26 +08:00
[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:
@ -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;
|
||||
|
Reference in New Issue
Block a user