From 127d1f85dd291b25fe63318546e81ebbf6497bf2 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 10 Jul 2018 17:09:39 +0100 Subject: [PATCH] Improve error message in microbenchmarks when flutter run lives too long (#19200) This should make it more obvious from the error what's gone wrong if we see a repeat of #19096 (previously the error was something like "Bad state: future already completed"). --- dev/devicelab/lib/tasks/microbenchmarks.dart | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dev/devicelab/lib/tasks/microbenchmarks.dart b/dev/devicelab/lib/tasks/microbenchmarks.dart index ded70a82d17..50a6bef3835 100644 --- a/dev/devicelab/lib/tasks/microbenchmarks.dart +++ b/dev/devicelab/lib/tasks/microbenchmarks.dart @@ -110,6 +110,7 @@ Future> _readJsonResults(Process process) { }); bool processWasKilledIntentionally = false; + bool resultsHaveBeenParsed = false; final StreamSubscription stdoutSub = process.stdout .transform(const Utf8Decoder()) .transform(const LineSplitter()) @@ -122,11 +123,27 @@ Future> _readJsonResults(Process process) { } if (line.contains(jsonEnd)) { + final String jsonOutput = jsonBuf.toString(); + + // If we end up here and have already parsed the results, it suggests that + // we have recieved output from another test because our `flutter run` + // process did not terminate correctly. + // https://github.com/flutter/flutter/issues/19096#issuecomment-402756549 + if (resultsHaveBeenParsed) { + throw 'Additional JSON was received after results has already been ' + 'processed. This suggests the `flutter run` process may have lived ' + 'past the end of our test and collected additional output from the ' + 'next test.\n\n' + 'The JSON below contains all collected output, including both from ' + 'the original test and what followed.\n\n' + '$jsonOutput'; + } + jsonStarted = false; processWasKilledIntentionally = true; + resultsHaveBeenParsed = true; // ignore: deprecated_member_use process.kill(ProcessSignal.SIGINT); // flutter run doesn't quit automatically - final String jsonOutput = jsonBuf.toString(); try { completer.complete(json.decode(jsonOutput)); } catch (ex) {