Roll sync async engine (#18454)
* Roll the engine. This engine includes a VM that defaults to sync-async. flutter/engine@c8eeee4 Roll the Dart VM.
This commit is contained in:
26
packages/flutter/test/engine/dart_test.dart
Normal file
26
packages/flutter/test/engine/dart_test.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
/// Verifies Dart semantics governed by flags set by Flutter tooling.
|
||||
void main() {
|
||||
group('Async', () {
|
||||
String greeting = 'hello';
|
||||
Future<void> changeGreeting() async {
|
||||
greeting += ' 1';
|
||||
await new Future<void>.value(null);
|
||||
greeting += ' 2';
|
||||
}
|
||||
test('execution of async method starts synchronously', () async {
|
||||
expect(greeting, 'hello');
|
||||
final Future<void> future = changeGreeting();
|
||||
expect(greeting, 'hello 1');
|
||||
await future;
|
||||
expect(greeting, 'hello 1 2');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -502,7 +502,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
testZone.runBinary(_runTestBody, testBody, invariantTester)
|
||||
.whenComplete(testCompletionHandler);
|
||||
timeout?.catchError(handleUncaughtError);
|
||||
asyncBarrier(); // When using AutomatedTestWidgetsFlutterBinding, this flushes the microtasks.
|
||||
return testCompleter.future;
|
||||
}
|
||||
|
||||
@@ -532,6 +531,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||
}
|
||||
|
||||
assert(inTest);
|
||||
asyncBarrier(); // When using AutomatedTestWidgetsFlutterBinding, this flushes the microtasks.
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -848,22 +848,23 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||
});
|
||||
|
||||
return new Future<Null>.microtask(() async {
|
||||
// testBodyResult is a Future that was created in the Zone of the
|
||||
// fakeAsync. This means that if we await it here, it will register a
|
||||
// microtask to handle the future _in the fake async zone_. We avoid this
|
||||
// by calling '.then' in the current zone. While flushing the microtasks
|
||||
// of the fake-zone below, the new future will be completed and can then
|
||||
// be used without fakeAsync.
|
||||
final Future<Null> resultFuture = testBodyResult.then<Null>((_) {
|
||||
// Do nothing.
|
||||
});
|
||||
|
||||
// Resolve interplay between fake async and real async calls.
|
||||
fakeAsync.flushMicrotasks();
|
||||
while (_pendingAsyncTasks != null) {
|
||||
await _pendingAsyncTasks.future;
|
||||
fakeAsync.flushMicrotasks();
|
||||
}
|
||||
|
||||
// If we get here and fakeAsync != _currentFakeAsync, then the test
|
||||
// probably timed out.
|
||||
|
||||
// testBodyResult is a Future that was created in the Zone of the
|
||||
// fakeAsync. This means that if we await it here, it will register a
|
||||
// microtask to handle the future _in the fake async zone_. We avoid this
|
||||
// by returning the wrapped microtask future that we've created _outside_
|
||||
// the fake async zone.
|
||||
return testBodyResult;
|
||||
return resultFuture;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user