Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: tools/gardening/lib/src/compare_failures_impl.dart

Issue 2987253002: Add test to compare-failures (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gardening/lib/src/client.dart ('k') | tools/gardening/lib/src/shard_data.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gardening/lib/src/compare_failures_impl.dart
diff --git a/tools/gardening/bin/compare_failures.dart b/tools/gardening/lib/src/compare_failures_impl.dart
similarity index 71%
copy from tools/gardening/bin/compare_failures.dart
copy to tools/gardening/lib/src/compare_failures_impl.dart
index de888914be7afeb83cc238627fb96899dad3d456..d3d77198061be4d9de8b975fb5ff855a0099b324 100644
--- a/tools/gardening/bin/compare_failures.dart
+++ b/tools/gardening/lib/src/compare_failures_impl.dart
@@ -7,53 +7,56 @@
/// Use this to detect flakiness of failures, especially timeouts.
import 'dart:async';
-import 'dart:io';
-import 'package:args/args.dart';
import 'package:gardening/src/buildbot_structures.dart';
+import 'package:gardening/src/buildbot_data.dart';
import 'package:gardening/src/client.dart';
import 'package:gardening/src/util.dart';
-void help(ArgParser argParser) {
- print('Given a <log-uri> finds all failing tests in that stdout. Then ');
- print('fetches earlier runs of the same bot and compares the results.');
- print('This tool is particularly useful to detect flakes and their ');
- print('frequency.');
- print('Usage: compare_failures [options] <log-uri>');
- print('where <log-uri> is the uri the stdio output of a failing test step');
- print('and options are:');
- print(argParser.usage);
+Future mainInternal(BuildbotClient client, List<String> args,
+ {int runCount: 10}) async {
+ printBuildResultsSummary(
+ await loadBuildResults(client, args, runCount: runCount));
}
-main(List<String> args) async {
- ArgParser argParser = createArgParser();
- argParser.addOption("run-count",
- defaultsTo: "10", help: "How many previous runs should be fetched");
- ArgResults argResults = argParser.parse(args);
- processArgResults(argResults);
-
- BuildbotClient client = argResults['logdog']
- ? new LogdogBuildbotClient()
- : new HttpBuildbotClient();
-
- var runCount = int.parse(argResults['run-count'], onError: (_) => null);
-
- if (argResults.rest.length != 1 || argResults['help'] || runCount == null) {
- help(argParser);
- if (argResults['help']) return;
- exit(1);
+/// Loads [BuildResult]s for the [runCount] last builds for the build(s) in
+/// [args]. [args] can be a list of [BuildGroup] names or a list of log uris.
+Future<Map<BuildUri, List<BuildResult>>> loadBuildResults(
+ BuildbotClient client, List<String> args,
+ {int runCount: 10}) async {
+ List<BuildUri> buildUriList = <BuildUri>[];
+ for (BuildGroup buildGroup in buildGroups) {
+ if (args.contains(buildGroup.groupName)) {
+ buildUriList.addAll(buildGroup.createUris(client.mostRecentBuildNumber));
+ }
+ }
+ if (buildUriList.isEmpty) {
+ for (String url in args) {
+ if (!url.endsWith('/text')) {
+ // Use the text version of the stdio log.
+ url += '/text';
+ }
+ Uri uri = Uri.parse(url);
+ BuildUri buildUri = new BuildUri(uri);
+ buildUriList.add(buildUri);
+ }
}
- String url = argResults.rest.first;
- if (!url.endsWith('/text')) {
- // Use the text version of the stdio log.
- url += '/text';
+ Map<BuildUri, List<BuildResult>> buildResults =
+ <BuildUri, List<BuildResult>>{};
+ for (BuildUri buildUri in buildUriList) {
+ List<BuildResult> results =
+ await readBuildResults(client, buildUri, runCount);
+ buildResults[buildUri] = results;
}
- Uri uri = Uri.parse(url);
- BuildUri buildUri = new BuildUri(uri);
- List<BuildResult> results =
- await readBuildResults(client, buildUri, runCount);
- print(generateBuildResultsSummary(buildUri, results));
- client.close();
+ return buildResults;
+}
+
+/// Prints summaries for the [buildResults].
+// TODO(johnniwinther): Improve printing of multiple [BuildUri] results.
+void printBuildResultsSummary(Map<BuildUri, List<BuildResult>> buildResults) {
+ buildResults.forEach((BuildUri buildUri, List<BuildResult> results) {
+ print(generateBuildResultsSummary(buildUri, results));
+ });
}
/// Creates a [BuildResult] for [buildUri] and, if it contains failures, the
@@ -154,5 +157,8 @@ String generateBuildResultsSummary(
sb.write('\n');
});
}
+ if (timeoutIds.isEmpty && errorIds.isEmpty) {
+ sb.write('No errors found.');
+ }
return sb.toString();
}
« no previous file with comments | « tools/gardening/lib/src/client.dart ('k') | tools/gardening/lib/src/shard_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698