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

Side by Side Diff: tools/gardening/test/test_client.dart

Issue 2987253002: Add test to compare-failures (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
« no previous file with comments | « tools/gardening/test/compare_failures_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Compares the test log of a build step with previous builds.
6 ///
7 /// Use this to detect flakiness of failures, especially timeouts.
8
9 import 'dart:async';
10 import 'dart:io';
11
12 import 'package:gardening/src/buildbot_loading.dart';
13 import 'package:gardening/src/buildbot_structures.dart';
14 import 'package:gardening/src/cache.dart';
15 import 'package:gardening/src/client.dart';
16 import 'package:gardening/src/util.dart';
17
18 class TestClient implements BuildbotClient {
19 BuildbotClient _client;
20
21 /// Creates a mock client using logs stored in the `data` folder. If [force]
22 /// is `true`, missing logs are pulling from http and stored in the `data`
23 /// folder.
24 TestClient({bool force: false})
25 : _client = force ? new HttpBuildbotClient() : null;
26
27 String computePath(BuildUri buildUri) {
28 return 'data/${buildUri.botName}/${buildUri.buildNumber}'
29 '/${buildUri.stepName.replaceAll(' ', '_')}.log';
30 }
31
32 Future<String> readData(BuildUri buildUri) async {
33 String path = computePath(buildUri);
34 File file = new File.fromUri(Platform.script.resolve(path));
35 if (!file.existsSync() && _client != null) {
36 await file.parent.create();
37 log('Pulling $buildUri from http');
38 BuildResult result = await _client.readResult(buildUri);
39 if (result.buildNumber != null) {
40 print('Writing test data to $file');
41 String text = await cache.read(
42 result.buildUri.logdogPath,
43 () => throw new ArgumentError(
44 'Cache missing for ${result.buildUri.logdogPath}.'));
45 await file.writeAsString(text);
46 }
47 }
48 assert(file.existsSync(), "File $file not found.");
49 log('Reading test data from $file');
50 return file.readAsString();
51 }
52
53 @override
54 Future<BuildResult> readResult(BuildUri buildUri) async {
55 String text = await readData(buildUri);
56 return parseTestStepResult(buildUri, text);
57 }
58
59 @override
60 void close() {
61 _client?.close();
62 }
63
64 @override
65 int get mostRecentBuildNumber => -1;
66 }
OLDNEW
« no previous file with comments | « tools/gardening/test/compare_failures_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698