From 3352a3fb488df4742ff323243d3dc44d9b7cd3e8 Mon Sep 17 00:00:00 2001
From: Vyacheslav Egorov <me@mrale.ph>
Date: Tue, 20 Mar 2018 19:30:06 +0100
Subject: [PATCH] Report an error if compilation during testing times out.
 (#15745)

* Report an error if compilation times out instead of waiting forever.

* Remove braces
---
 .../lib/src/test/flutter_platform.dart              | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart
index a9b27384750..b82e0aa45b9 100644
--- a/packages/flutter_tools/lib/src/test/flutter_platform.dart
+++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart
@@ -144,10 +144,10 @@ class _Compiler {
           printTrace('Compiling ${request.path}');
           compiler ??= createCompiler();
           suppressOutput = false;
-          final String outputPath = await compiler.recompile(request.path,
+          final String outputPath = await handleTimeout(compiler.recompile(request.path,
             <String>[request.path],
             outputPath: outputDill.path,
-          );
+          ), request.path);
 
           // Check if the compiler produced the output. If it failed then
           // outputPath would be null. In this case pass null upwards to the
@@ -180,13 +180,20 @@ class _Compiler {
   Future<String> compile(String mainDart) {
     final Completer<String> completer = new Completer<String>();
     compilerController.add(new _CompilationRequest(mainDart, completer));
-    return completer.future;
+    return handleTimeout(completer.future, mainDart);
   }
 
   Future<dynamic> shutdown() async {
     await compiler.shutdown();
     compiler = null;
   }
+
+  static Future<String> handleTimeout(Future<String> value, String path) {
+    return value.timeout(const Duration(minutes: 5), onTimeout: () {
+      printError('Compilation of $path timed out after 5 minutes.');
+      return null;
+    });
+  }
 }
 
 class _FlutterPlatform extends PlatformPlugin {
-- 
GitLab