diff --git a/dev/bots/test.dart b/dev/bots/test.dart index e3101f553e..d30282b574 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -32,6 +32,9 @@ const Map _kShards = const { '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 _runTests({List options: const []}) 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, ['drive', '--use-existing-app'] @@ -180,6 +189,7 @@ Future _runTests({List options: const []}) 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 _runCommand(String executable, List 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 _runCommand(String executable, List 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 ints) => ints).toList())); - print(utf8.decode((await savedStderr).expand((List ints) => ints).toList())); + stdout.writeln(utf8.decode((await savedStdout).expand((List ints) => ints).toList())); + stderr.writeln(utf8.decode((await savedStderr).expand((List ints) => ints).toList())); } print( '$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset\n' @@ -352,11 +366,12 @@ Future _runCommand(String executable, List arguments, { } Future _runFlutterTest(String workingDirectory, { - String script, - bool expectFailure: false, - bool printOutput: true, - List options: const [], - bool skip: false, + String script, + bool expectFailure: false, + bool printOutput: true, + List options: const [], + bool skip: false, + Duration timeout: _kLongTimeout, }) { final List args = ['test']..addAll(options); if (flutterTestArgs != null && flutterTestArgs.isNotEmpty) @@ -368,6 +383,7 @@ Future _runFlutterTest(String workingDirectory, { expectFailure: expectFailure, printOutput: printOutput, skip: skip, + timeout: timeout, ); }