Add a timeout to bot tests. (#16666)

This will catch the case where tests hang -- and it will
force them to fail so that we see the output from the test.
This commit is contained in:
Todd Volkert
2018-04-17 10:00:06 -07:00
committed by GitHub
parent c7df2619d7
commit 58d3493445

View File

@@ -32,6 +32,9 @@ const Map<String, ShardRunner> _kShards = const <String, ShardRunner>{
'coverage': _runCoverage,
};
const Duration _kLongTimeout = const Duration(minutes: 45);
const Duration _kShortTimeout = const Duration(minutes: 5);
/// When you call this, you can pass additional arguments to pass custom
/// arguments to flutter test. For example, you might want to call this
/// script with the parameter --local-engine=host_debug_unopt to
@@ -143,35 +146,41 @@ Future<Null> _runTests({List<String> options: const <String>[]}) async {
options: options,
expectFailure: true,
printOutput: false,
timeout: _kShortTimeout,
);
await _runFlutterTest(automatedTests,
script: path.join('test_smoke_test', 'pass_test.dart'),
options: options,
printOutput: false,
timeout: _kShortTimeout,
);
await _runFlutterTest(automatedTests,
script: path.join('test_smoke_test', 'crash1_test.dart'),
options: options,
expectFailure: true,
printOutput: false,
timeout: _kShortTimeout,
);
await _runFlutterTest(automatedTests,
script: path.join('test_smoke_test', 'crash2_test.dart'),
options: options,
expectFailure: true,
printOutput: false,
timeout: _kShortTimeout,
);
await _runFlutterTest(automatedTests,
script: path.join('test_smoke_test', 'syntax_error_test.broken_dart'),
options: options,
expectFailure: true,
printOutput: false,
timeout: _kShortTimeout,
);
await _runFlutterTest(automatedTests,
script: path.join('test_smoke_test', 'missing_import_test.broken_dart'),
options: options,
expectFailure: true,
printOutput: false,
timeout: _kShortTimeout,
);
await _runCommand(flutter,
<String>['drive', '--use-existing-app']
@@ -180,6 +189,7 @@ Future<Null> _runTests({List<String> options: const <String>[]}) async {
workingDirectory: path.join(flutterRoot, 'packages', 'flutter_driver'),
expectFailure: true,
printOutput: false,
timeout: _kShortTimeout,
);
// Verify that we correctly generated the version file.
@@ -313,6 +323,7 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
bool expectFailure: false,
bool printOutput: true,
bool skip: false,
Duration timeout: _kLongTimeout,
}) async {
final String commandDescription = '${path.relative(executable, from: workingDirectory)} ${arguments.join(' ')}';
final String relativeWorkingDir = path.relative(workingDirectory);
@@ -336,11 +347,14 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
savedStderr = process.stderr.toList();
}
final int exitCode = await process.exitCode;
final int exitCode = await process.exitCode.timeout(timeout, onTimeout: () {
stderr.writeln('Process timed out after $timeout');
return expectFailure ? 0 : 1;
});
if ((exitCode == 0) == expectFailure) {
if (!printOutput) {
print(utf8.decode((await savedStdout).expand((List<int> ints) => ints).toList()));
print(utf8.decode((await savedStderr).expand((List<int> ints) => ints).toList()));
stdout.writeln(utf8.decode((await savedStdout).expand((List<int> ints) => ints).toList()));
stderr.writeln(utf8.decode((await savedStderr).expand((List<int> ints) => ints).toList()));
}
print(
'$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset\n'
@@ -352,11 +366,12 @@ Future<Null> _runCommand(String executable, List<String> arguments, {
}
Future<Null> _runFlutterTest(String workingDirectory, {
String script,
bool expectFailure: false,
bool printOutput: true,
List<String> options: const <String>[],
bool skip: false,
String script,
bool expectFailure: false,
bool printOutput: true,
List<String> options: const <String>[],
bool skip: false,
Duration timeout: _kLongTimeout,
}) {
final List<String> args = <String>['test']..addAll(options);
if (flutterTestArgs != null && flutterTestArgs.isNotEmpty)
@@ -368,6 +383,7 @@ Future<Null> _runFlutterTest(String workingDirectory, {
expectFailure: expectFailure,
printOutput: printOutput,
skip: skip,
timeout: timeout,
);
}