From fb18ac650ef9c814f403509c4d7315918eac8dd2 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Sat, 21 Apr 2018 19:52:46 -0700 Subject: [PATCH] Notify test timeouts differently than test completions. (#16842) This avoids notifying the coverage collector that we completed the test when in fact we timed out, which in turn avoids a downstream exception caused by the fact that coverage collector assumes it has a valid observatory port by which it can gather coverage data. Fixes https://github.com/flutter/flutter/issues/16839 --- .../lib/src/test/coverage_collector.dart | 2 +- .../lib/src/test/flutter_platform.dart | 18 +++++++++++++++--- .../flutter_tools/lib/src/test/watcher.dart | 13 ++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/test/coverage_collector.dart b/packages/flutter_tools/lib/src/test/coverage_collector.dart index de973e7236..43dfc86bcd 100644 --- a/packages/flutter_tools/lib/src/test/coverage_collector.dart +++ b/packages/flutter_tools/lib/src/test/coverage_collector.dart @@ -18,7 +18,7 @@ class CoverageCollector extends TestWatcher { Map _globalHitmap; @override - Future onFinishedTests(ProcessEvent event) async { + Future onFinishedTest(ProcessEvent event) async { printTrace('test ${event.childIndex}: collecting coverage'); await collectCoverage(event.process, event.observatoryUri); } diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 1eace64ce1..f591ead33b 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -497,9 +497,21 @@ class _FlutterPlatform extends PlatformPlugin { break; } - if (subprocessActive && watcher != null) { - await watcher.onFinishedTests( - new ProcessEvent(ourTestCount, process, processObservatoryUri)); + if (watcher != null) { + switch (initialResult) { + case _InitialResult.crashed: + await watcher.onTestCrashed(new ProcessEvent(ourTestCount, process)); + break; + case _InitialResult.timedOut: + await watcher.onTestTimedOut(new ProcessEvent(ourTestCount, process)); + break; + case _InitialResult.connected: + if (subprocessActive) { + await watcher.onFinishedTest( + new ProcessEvent(ourTestCount, process, processObservatoryUri)); + } + break; + } } } catch (error, stack) { printTrace('test $ourTestCount: error caught during test; ${controllerSinkClosed ? "reporting to console" : "sending to test framework"}'); diff --git a/packages/flutter_tools/lib/src/test/watcher.dart b/packages/flutter_tools/lib/src/test/watcher.dart index 497531592a..e03326f96a 100644 --- a/packages/flutter_tools/lib/src/test/watcher.dart +++ b/packages/flutter_tools/lib/src/test/watcher.dart @@ -6,7 +6,7 @@ import 'dart:async'; import '../base/io.dart' show Process; /// Callbacks for reporting progress while running tests. -class TestWatcher { +abstract class TestWatcher { /// Called after a child process starts. /// /// If startPaused was true, the caller needs to resume in Observatory to @@ -17,12 +17,19 @@ class TestWatcher { /// /// The child process won't exit until this method completes. /// Not called if the process died. - Future onFinishedTests(ProcessEvent event) async {} + Future onFinishedTest(ProcessEvent event) async {} + + /// Called when the test process crashed before connecting to test harness. + Future onTestCrashed(ProcessEvent event) async {} + + /// Called if we timed out waiting for the test process to connect to test + /// harness. + Future onTestTimedOut(ProcessEvent event) async {} } /// Describes a child process started during testing. class ProcessEvent { - ProcessEvent(this.childIndex, this.process, this.observatoryUri); + ProcessEvent(this.childIndex, this.process, [this.observatoryUri]); /// The index assigned when the child process was launched. ///