Unverified Commit 3ced55a7 authored by Florian Loitsch's avatar Florian Loitsch Committed by GitHub

Sync async2 (#17964)

Enable --sync-async in Flutter.
Fixes #16801 
parent bb887664
...@@ -43,7 +43,10 @@ Who lives, who dies, who tells your story\? ...@@ -43,7 +43,10 @@ Who lives, who dies, who tells your story\?
When the exception was thrown, this was the stack: When the exception was thrown, this was the stack:
#[0-9]+ +main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:16:9\) #[0-9]+ +main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:16:9\)
#[0-9]+ +main.<anonymous closure> \(.+[/\\]dev[/\\]automated_tests[/\\]flutter_test[/\\]exception_handling_test\.dart:15:77\) #[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]binding.dart:[0-9]+:[0-9]+\)
#[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]binding.dart:[0-9]+:[0-9]+\)
#[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]binding.dart:[0-9]+:[0-9]+\)
#[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]binding.dart:[0-9]+:[0-9]+\)
#[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]widget_tester\.dart:[0-9]+:[0-9]+\) #[0-9]+ +.+ \(package:flutter_test[/\\]src[/\\]widget_tester\.dart:[0-9]+:[0-9]+\)
<<skip until matching line>> <<skip until matching line>>
^\(elided [0-9]+ .+\)$ ^\(elided [0-9]+ .+\)$
......
...@@ -14,7 +14,10 @@ class TestTestBinding extends AutomatedTestWidgetsFlutterBinding { ...@@ -14,7 +14,10 @@ class TestTestBinding extends AutomatedTestWidgetsFlutterBinding {
Future<Null> guardedHelper(WidgetTester tester) { Future<Null> guardedHelper(WidgetTester tester) {
return TestAsyncUtils.guard(() async { return TestAsyncUtils.guard(() async {
await tester.pumpWidget(const Text('Hello')); await tester.pumpWidget(const Directionality(
textDirection: TextDirection.ltr,
child: const Text('Hello'),
));
}); });
} }
......
...@@ -490,6 +490,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -490,6 +490,12 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
} }
Future<Null> _runTestBody(Future<Null> testBody(), VoidCallback invariantTester) async { Future<Null> _runTestBody(Future<Null> testBody(), VoidCallback invariantTester) async {
// Delay this function by a microtask.
// Otherwise it will open a scope immediately, which is then open when
// the `asyncBarrier` is invoked. The `asyncBarrier` is immediately
// following the call to `testZone.runBinary(_runTestBody)`, so delaying
// by one microtask is enough to ensure that the timing is correct.
await new Future<Null>.microtask(() {});
assert(inTest); assert(inTest);
runApp(new Container(key: new UniqueKey(), child: _preTestMessage)); // Reset the tree to a known state. runApp(new Container(key: new UniqueKey(), child: _preTestMessage)); // Reset the tree to a known state.
...@@ -767,6 +773,12 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -767,6 +773,12 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}); });
return new Future<Null>.microtask(() async { return new Future<Null>.microtask(() async {
// Run all queued microtasks.
await new Future<Null>.microtask(() {});
// When the test had an exception, the test-framework already
// ran the teardown functions, removing the _fakeAsync function.
if (_fakeAsync == null)
return null;
// Resolve interplay between fake async and real async calls. // Resolve interplay between fake async and real async calls.
_fakeAsync.flushMicrotasks(); _fakeAsync.flushMicrotasks();
while (_pendingAsyncTasks != null) { while (_pendingAsyncTasks != null) {
...@@ -983,6 +995,13 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -983,6 +995,13 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override @override
void handleBeginFrame(Duration rawTimeStamp) { void handleBeginFrame(Duration rawTimeStamp) {
// Don't run this function when `handleBeginFrame` was invoked
// immediately before without a call of `handleDrawFrame` in between.
// TODO(floitsch): Remove this line when the spurious calls from the
// framework don't happen anymore. See
// https://github.com/flutter/flutter/issues/17963
if (_doDrawThisFrame != null)
return;
assert(_doDrawThisFrame == null); assert(_doDrawThisFrame == null);
if (_expectingFrame || if (_expectingFrame ||
(framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.fullyLive) || (framePolicy == LiveTestWidgetsFlutterBindingFramePolicy.fullyLive) ||
...@@ -997,6 +1016,13 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -997,6 +1016,13 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override @override
void handleDrawFrame() { void handleDrawFrame() {
// Don't run this function when `handleBeginFrame` wasn't invoked
// immediately before.
// TODO(floitsch): Remove this line when the spurious calls from the
// framework don't happen anymore. See
// https://github.com/flutter/flutter/issues/17963
if (_doDrawThisFrame == null)
return;
assert(_doDrawThisFrame != null); assert(_doDrawThisFrame != null);
if (_doDrawThisFrame) if (_doDrawThisFrame)
super.handleDrawFrame(); super.handleDrawFrame();
......
...@@ -120,6 +120,7 @@ class KernelCompiler { ...@@ -120,6 +120,7 @@ class KernelCompiler {
'--sdk-root', '--sdk-root',
sdkRoot, sdkRoot,
'--strong', '--strong',
'--sync-async',
'--target=flutter', '--target=flutter',
]; ];
if (trackWidgetCreation) if (trackWidgetCreation)
...@@ -252,6 +253,7 @@ class ResidentCompiler { ...@@ -252,6 +253,7 @@ class ResidentCompiler {
_sdkRoot, _sdkRoot,
'--incremental', '--incremental',
'--strong', '--strong',
'--sync-async',
'--target=flutter', '--target=flutter',
]; ];
if (outputPath != null) { if (outputPath != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment