Unverified Commit 58d34934 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

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