print intermediate and raw A/B results when not silent (#54676)

* print intermediate A/B results when not silent
* print raw A/B results when in loud mode
* add tests; handle missing metrics more gracefully
* use less fancy section header on Windows
This commit is contained in:
Yegor
2020-04-16 14:36:42 -07:00
committed by GitHub
parent ce83aaf38d
commit 20803507fd
6 changed files with 187 additions and 18 deletions

View File

@@ -0,0 +1,51 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_devicelab/framework/ab.dart';
import 'common.dart';
void main() {
test('ABTest', () {
final ABTest ab = ABTest();
for (int i = 0; i < 5; i++) {
ab.addAResult(<String, dynamic>{
'data': <String, dynamic>{
'i': i,
'j': 10 * i,
'not_a_metric': 'something',
},
'benchmarkScoreKeys': <String>['i', 'j'],
});
ab.addBResult(<String, dynamic>{
'data': <String, dynamic>{
'i': i + 1,
'k': 10 * i + 1,
},
'benchmarkScoreKeys': <String>['i', 'k'],
});
}
expect(
ab.rawResults(),
'i:\n'
' A:\t0.00\t1.00\t2.00\t3.00\t4.00\t\n'
' B:\t1.00\t2.00\t3.00\t4.00\t5.00\t\n'
'j:\n'
' A:\t0.00\t10.00\t20.00\t30.00\t40.00\t\n'
' B:\tN/A\n'
'k:\n'
' A:\tN/A\n'
' B:\t1.00\t11.00\t21.00\t31.00\t41.00\t\n',
);
expect(
ab.printSummary(),
'Score\tAverage A (noise)\tAverage B (noise)\tSpeed-up\n'
'i\t2.00 (70.71%)\t3.00 (47.14%)\t0.67x\t\n'
'j\t20.00 (70.71%)\t\t\n'
'k\t\t21.00 (67.34%)\t\n');
});
}

View File

@@ -14,21 +14,26 @@ void main() {
const ProcessManager processManager = LocalProcessManager();
group('run.dart script', () {
Future<ProcessResult> runScript(List<String> testNames) async {
final String dart = path.absolute(path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', 'dart'));
Future<ProcessResult> runScript(List<String> testNames,
[List<String> otherArgs = const <String>[]]) async {
final String dart = path.absolute(
path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', 'dart'));
final ProcessResult scriptProcess = processManager.runSync(<String>[
dart,
'bin/run.dart',
...otherArgs,
for (final String testName in testNames) ...<String>['-t', testName],
]);
return scriptProcess;
}
Future<void> expectScriptResult(List<String> testNames, int expectedExitCode) async {
Future<void> expectScriptResult(
List<String> testNames, int expectedExitCode) async {
final ProcessResult result = await runScript(testNames);
expect(result.exitCode, expectedExitCode,
reason: '[ stderr from test process ]\n\n${result.stderr}\n\n[ end of stderr ]'
'\n\n[ stdout from test process ]\n\n${result.stdout}\n\n[ end of stdout ]');
reason:
'[ stderr from test process ]\n\n${result.stderr}\n\n[ end of stderr ]'
'\n\n[ stdout from test process ]\n\n${result.stdout}\n\n[ end of stdout ]');
}
test('exits with code 0 when succeeds', () async {
@@ -36,7 +41,8 @@ void main() {
});
test('accepts file paths', () async {
await expectScriptResult(<String>['bin/tasks/smoke_test_success.dart'], 0);
await expectScriptResult(
<String>['bin/tasks/smoke_test_success.dart'], 0);
});
test('rejects invalid file paths', () async {
@@ -56,12 +62,66 @@ void main() {
}, skip: true); // https://github.com/flutter/flutter/issues/53707
test('exits with code 1 when results are mixed', () async {
await expectScriptResult(<String>[
await expectScriptResult(
<String>[
'smoke_test_failure',
'smoke_test_success',
],
1,
);
});
test('runs A/B test', () async {
final ProcessResult result = await runScript(
<String>['smoke_test_success'],
<String>['--ab=2', '--local-engine=host_debug_unopt'],
);
expect(result.exitCode, 0);
String sectionHeader = !Platform.isWindows
? '═════════════════════════╡ ••• A/B results so far ••• ╞═════════════════════════'
: 'A/B results so far';
expect(
result.stdout,
contains(
'$sectionHeader\n'
'\n'
'Score\tAverage A (noise)\tAverage B (noise)\tSpeed-up\n'
'metric1\t42.00 (0.00%)\t42.00 (0.00%)\t1.00x\t\n'
'metric2\t123.00 (0.00%)\t123.00 (0.00%)\t1.00x\t\n',
),
);
sectionHeader = !Platform.isWindows
? '════════════════════════════╡ ••• Raw results ••• ╞═════════════════════════════'
: 'Raw results';
expect(
result.stdout,
contains(
'$sectionHeader\n'
'\n'
'metric1:\n'
' A:\t42.00\t42.00\t\n'
' B:\t42.00\t42.00\t\n'
'metric2:\n'
' A:\t123.00\t123.00\t\n'
' B:\t123.00\t123.00\t\n',
),
);
sectionHeader = !Platform.isWindows
? '═════════════════════════╡ ••• Final A/B results ••• ╞══════════════════════════'
: 'Final A/B results';
expect(
result.stdout,
contains(
'$sectionHeader\n'
'\n'
'Score\tAverage A (noise)\tAverage B (noise)\tSpeed-up\n'
'metric1\t42.00 (0.00%)\t42.00 (0.00%)\t1.00x\t\n'
'metric2\t123.00 (0.00%)\t123.00 (0.00%)\t1.00x\t\n',
),
);
});
});
}