Rerun devicelab task from test runner (#86394)
This commit is contained in:
@@ -47,6 +47,9 @@ class Cocoon {
|
||||
/// Url used to send results to.
|
||||
static const String baseCocoonApiUrl = 'https://flutter-dashboard.appspot.com/api';
|
||||
|
||||
/// Threshold to auto retry a failed test.
|
||||
static const int retryNumber = 2;
|
||||
|
||||
/// Underlying [FileSystem] to use.
|
||||
final FileSystem fs;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
// import 'dart:core' as core;
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_devicelab/common.dart';
|
||||
@@ -15,6 +16,16 @@ import 'devices.dart';
|
||||
import 'task_result.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
/// Run a list of tasks.
|
||||
///
|
||||
/// For each task, an auto rerun will be triggered when task fails.
|
||||
///
|
||||
/// If the task succeeds the first time, it will be recorded as successful.
|
||||
///
|
||||
/// If the task fails first, but gets passed in the end, the
|
||||
/// test will be recorded as successful but with a flake flag.
|
||||
///
|
||||
/// If the task fails all reruns, it will be recorded as failed.
|
||||
Future<void> runTasks(
|
||||
List<String> taskNames, {
|
||||
bool exitOnFirstTestFailure = false,
|
||||
@@ -26,33 +37,45 @@ Future<void> runTasks(
|
||||
String? luciBuilder,
|
||||
String? resultsPath,
|
||||
List<String>? taskArgs,
|
||||
@visibleForTesting Map<String, String>? isolateParams,
|
||||
@visibleForTesting Function(String) print = print,
|
||||
@visibleForTesting List<String>? logs,
|
||||
}) async {
|
||||
for (final String taskName in taskNames) {
|
||||
section('Running task "$taskName"');
|
||||
final TaskResult result = await runTask(
|
||||
taskName,
|
||||
deviceId: deviceId,
|
||||
localEngine: localEngine,
|
||||
localEngineSrcPath: localEngineSrcPath,
|
||||
silent: silent,
|
||||
taskArgs: taskArgs,
|
||||
);
|
||||
|
||||
print('Task result:');
|
||||
print(const JsonEncoder.withIndent(' ').convert(result));
|
||||
section('Finished task "$taskName"');
|
||||
|
||||
if (resultsPath != null) {
|
||||
final Cocoon cocoon = Cocoon();
|
||||
await cocoon.writeTaskResultToFile(
|
||||
builderName: luciBuilder,
|
||||
gitBranch: gitBranch,
|
||||
result: result,
|
||||
TaskResult result = TaskResult.success(null);
|
||||
int retry = 0;
|
||||
while (retry <= Cocoon.retryNumber) {
|
||||
result = await rerunTask(
|
||||
taskName,
|
||||
deviceId: deviceId,
|
||||
localEngine: localEngine,
|
||||
localEngineSrcPath: localEngineSrcPath,
|
||||
silent: silent,
|
||||
taskArgs: taskArgs,
|
||||
resultsPath: resultsPath,
|
||||
gitBranch: gitBranch,
|
||||
luciBuilder: luciBuilder,
|
||||
isolateParams: isolateParams,
|
||||
);
|
||||
|
||||
section('Flaky status for "$taskName"');
|
||||
if (!result.succeeded) {
|
||||
retry++;
|
||||
} else {
|
||||
if (retry > 0) {
|
||||
print('Total ${retry+1} executions: $retry failures and 1 success');
|
||||
print('flaky: true');
|
||||
} else {
|
||||
print('Total ${retry+1} executions: 1 success');
|
||||
print('flaky: false');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.succeeded) {
|
||||
print('Total $retry executions: 0 success');
|
||||
print('flaky: false');
|
||||
exitCode = 1;
|
||||
if (exitOnFirstTestFailure) {
|
||||
return;
|
||||
@@ -61,6 +84,48 @@ Future<void> runTasks(
|
||||
}
|
||||
}
|
||||
|
||||
/// A rerun wrapper for `runTask`.
|
||||
///
|
||||
/// This separates reruns in separate sections.
|
||||
Future<TaskResult> rerunTask(
|
||||
String taskName, {
|
||||
String? deviceId,
|
||||
String? localEngine,
|
||||
String? localEngineSrcPath,
|
||||
bool silent = false,
|
||||
List<String>? taskArgs,
|
||||
String? resultsPath,
|
||||
String? gitBranch,
|
||||
String? luciBuilder,
|
||||
@visibleForTesting Map<String, String>? isolateParams,
|
||||
}) async {
|
||||
section('Running task "$taskName"');
|
||||
final TaskResult result = await runTask(
|
||||
taskName,
|
||||
deviceId: deviceId,
|
||||
localEngine: localEngine,
|
||||
localEngineSrcPath: localEngineSrcPath,
|
||||
silent: silent,
|
||||
taskArgs: taskArgs,
|
||||
isolateParams: isolateParams,
|
||||
);
|
||||
|
||||
print('Task result:');
|
||||
print(const JsonEncoder.withIndent(' ').convert(result));
|
||||
section('Finished task "$taskName"');
|
||||
|
||||
if (resultsPath != null) {
|
||||
final Cocoon cocoon = Cocoon();
|
||||
await cocoon.writeTaskResultToFile(
|
||||
builderName: luciBuilder,
|
||||
gitBranch: gitBranch,
|
||||
result: result,
|
||||
resultsPath: resultsPath,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Runs a task in a separate Dart VM and collects the result using the VM
|
||||
/// service protocol.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user