dart-sdk/tests/lib/async/future_regression_48493_test.dart
Lasse R.H. Nielsen 6c86fc44a6 Reland "Fix bug in Completer.complete."
This reverts commit 212d5e3a31.
This reapplies commit 3688a4723c.

CoreLibraryReviewExempt: Refactoring and relanding.
Change-Id: I9b52ef4073bfff50699919f8a5b85e5ff66d0c3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258929
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
Auto-Submit: Lasse Nielsen <lrn@google.com>
2023-05-02 19:33:57 +00:00

31 lines
1 KiB
Dart

// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for http://dartbug.com/48493
//
// The `Completer.complete` method, given an already completed `_Future`
// with a value result, will complete the `Completer.future` synchronously.
import 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
void main() async {
asyncStart();
var completer = Completer<int>(); // Not synchronous.
var future = Future<int>.value(4);
await future; // Ensure future completed.
bool thenRun = false;
completer.future.then((_) {
thenRun = true;
});
Expect.isFalse(thenRun, "Sanity check");
completer.complete(future);
Expect.isFalse(thenRun, "Ran early"); // Bug would cause this to fail.
await Future(() {}); // Await timer, all microtasks completed.
Expect.isTrue(thenRun, "Did not run as microtask");
asyncEnd();
}