From 0c7a9da98f46e24eb10749b2edd7ce9eb2f3b027 Mon Sep 17 00:00:00 2001 From: Yegor Date: Wed, 11 Jan 2017 14:29:21 -0800 Subject: [PATCH] microbenchmarks: single-line JSON; consolidate #7433 workaround (#7450) - output single-line JSON because iOS 9.x cannot output more than one line - move the workaround for #7433 into LiveTestWidgetsFlutterBinding so that it works in all cases (e.g. animation_bench.dart on iOS) --- dev/benchmarks/microbenchmarks/lib/common.dart | 6 +++--- dev/benchmarks/microbenchmarks/lib/stocks/build_bench.dart | 1 - dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart | 1 - dev/devicelab/lib/tasks/microbenchmarks.dart | 5 +---- packages/flutter_test/lib/src/binding.dart | 2 ++ 5 files changed, 6 insertions(+), 9 deletions(-) diff --git a/dev/benchmarks/microbenchmarks/lib/common.dart b/dev/benchmarks/microbenchmarks/lib/common.dart index 7a9796e47f..5100fe3a8b 100644 --- a/dev/benchmarks/microbenchmarks/lib/common.dart +++ b/dev/benchmarks/microbenchmarks/lib/common.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:convert' show JsonEncoder; +import 'dart:convert' show JSON; import 'package:meta/meta.dart'; @@ -46,8 +46,8 @@ class BenchmarkResultPrinter { } String _printJson() { - const JsonEncoder encoder = const JsonEncoder.withIndent(' '); - return encoder.convert(new Map.fromIterable(_results, + return JSON.encode(new Map.fromIterable( + _results, key: (_BenchmarkResult result) => result.name, value: (_BenchmarkResult result) => result.value, )); diff --git a/dev/benchmarks/microbenchmarks/lib/stocks/build_bench.dart b/dev/benchmarks/microbenchmarks/lib/stocks/build_bench.dart index 0466f9776d..cb370cd974 100644 --- a/dev/benchmarks/microbenchmarks/lib/stocks/build_bench.dart +++ b/dev/benchmarks/microbenchmarks/lib/stocks/build_bench.dart @@ -21,7 +21,6 @@ Future main() async { await benchmarkWidgets((WidgetTester tester) async { stocks.main(); await tester.pump(); // Start startup animation - new Timer(const Duration(milliseconds: 1100), () { }); // workaround for https://github.com/flutter/flutter/issues/7433 await tester.pump(const Duration(seconds: 1)); // Complete startup animation await tester.tapAt(new Point(20.0, 20.0)); // Open drawer await tester.pump(); // Start drawer animation diff --git a/dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart b/dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart index bb5753428c..b9fd709af3 100644 --- a/dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart +++ b/dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart @@ -20,7 +20,6 @@ Future main() async { await benchmarkWidgets((WidgetTester tester) async { stocks.main(); await tester.pump(); // Start startup animation - new Timer(const Duration(milliseconds: 1100), () { }); // workaround for https://github.com/flutter/flutter/issues/7433 await tester.pump(const Duration(seconds: 1)); // Complete startup animation await tester.tapAt(new Point(20.0, 20.0)); // Open drawer await tester.pump(); // Start drawer animation diff --git a/dev/devicelab/lib/tasks/microbenchmarks.dart b/dev/devicelab/lib/tasks/microbenchmarks.dart index 431ed7dd36..c9d47c65dd 100644 --- a/dev/devicelab/lib/tasks/microbenchmarks.dart +++ b/dev/devicelab/lib/tasks/microbenchmarks.dart @@ -41,10 +41,7 @@ TaskFunction createMicrobenchmarkTask() { allResults.addAll(await _runMicrobench('lib/stocks/layout_bench.dart')); allResults.addAll(await _runMicrobench('lib/stocks/build_bench.dart')); allResults.addAll(await _runMicrobench('lib/gestures/velocity_tracker_bench.dart')); - if (deviceOperatingSystem == DeviceOperatingSystem.android) { - // TODO(yjbanov): Run on iOS when https://github.com/flutter/flutter/issues/7433 is fixed. - allResults.addAll(await _runMicrobench('lib/stocks/animation_bench.dart')); - } + allResults.addAll(await _runMicrobench('lib/stocks/animation_bench.dart')); return new TaskResult.success(allResults, benchmarkScoreKeys: allResults.keys.toList()); }; diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 43650dcb5a..2a880c897e 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -632,6 +632,8 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { super.handleBeginFrame(rawTimeStamp); if (_expectingFrame) { assert(_pendingFrame != null); + // TODO(yjbanov): workaroud for https://github.com/flutter/flutter/issues/7433 + Timer.run(() {}); // forces runtime to flush Completer.complete() microtask _pendingFrame.complete(); // unlocks the test API _pendingFrame = null; _expectingFrame = false;