Skip to content

Commit 2cf8502

Browse files
authored
Implement "iterations" directive for customer tests (flutter#124541)
Implement "iterations" directive for customer tests
1 parent 5da6c4d commit 2cf8502

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

dev/customer_testing/lib/customer_test.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class CustomerTest {
1414
final List<String> fetch = <String>[];
1515
final List<Directory> update = <Directory>[];
1616
final List<String> test = <String>[];
17+
int? iterations;
1718
bool hasTests = false;
1819
for (final String line in testFile.readAsLinesSync().map((String line) => line.trim())) {
1920
if (line.isEmpty) {
@@ -26,6 +27,14 @@ class CustomerTest {
2627
fetch.add(line.substring(6));
2728
} else if (line.startsWith('update=')) {
2829
update.add(Directory(line.substring(7)));
30+
} else if (line.startsWith('iterations=')) {
31+
if (iterations != null) {
32+
throw const FormatException('Cannot specify "iterations" directive multiple times.');
33+
}
34+
iterations = int.parse(line.substring(11));
35+
if (iterations < 1) {
36+
throw const FormatException('The "iterations" directive must have a positive integer value.');
37+
}
2938
} else if (line.startsWith('test=')) {
3039
hasTests = true;
3140
test.add(line.substring(5));
@@ -84,10 +93,11 @@ class CustomerTest {
8493
List<String>.unmodifiable(fetch),
8594
List<Directory>.unmodifiable(update),
8695
List<String>.unmodifiable(test),
96+
iterations,
8797
);
8898
}
8999

90-
const CustomerTest._(this.contacts, this.fetch, this.update, this.tests);
100+
const CustomerTest._(this.contacts, this.fetch, this.update, this.tests, this.iterations);
91101

92102
// (e-mail regexp from HTML standard)
93103
static final RegExp _email = RegExp(r"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$");
@@ -98,4 +108,5 @@ class CustomerTest {
98108
final List<String> fetch;
99109
final List<Directory> update;
100110
final List<String> tests;
111+
final int? iterations;
101112
}

dev/customer_testing/lib/runner.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ Future<bool> runTests({
133133
if (verbose) {
134134
print('Running tests...');
135135
}
136+
if (instructions.iterations != null && instructions.iterations! < repeat) {
137+
if (verbose) {
138+
final String s = instructions.iterations == 1 ? '' : 's';
139+
print('Limiting to ${instructions.iterations} round$s rather than $repeat rounds because of "iterations" directive.');
140+
}
141+
repeat = instructions.iterations!;
142+
}
143+
final Stopwatch stopwatch = Stopwatch()..start();
136144
for (int iteration = 0; iteration < repeat; iteration += 1) {
137145
if (verbose && repeat > 1) {
138146
print('Round ${iteration + 1} of $repeat.');
@@ -146,8 +154,9 @@ Future<bool> runTests({
146154
}
147155
}
148156
}
157+
stopwatch.stop();
149158
if (verbose && success) {
150-
print('Tests finished.');
159+
print('Tests finished in ${(stopwatch.elapsed.inSeconds / repeat).toStringAsFixed(2)} seconds per iteration.');
151160
}
152161
}
153162
}

dev/customer_testing/run_tests.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Future<bool> run(List<String> arguments) async {
2424
..addOption(
2525
'repeat',
2626
defaultsTo: '1',
27-
help: 'How many times to run each test. Set to a high value to look for flakes.',
27+
help: 'How many times to run each test. Set to a high value to look for flakes. If a test specifies a number of iterations, the lower of the two values is used.',
2828
valueHelp: 'count',
2929
)
3030
..addOption(

0 commit comments

Comments
 (0)