Files
sdk/tests/language/async/error_timing_test.dart
T
Lasse R.H. Nielsen f8086c81ae Collect all test-related files in package:expect.
Collects files from `package:async_helper` and `tests/language`
that are generally useful, so that all test-related helpers are
in `package:expect`.

Moves the two libraries from `package:async_helper` into `package:expect`,
and the `tests/language/static_type_helper.dart` file too.

Deprecates `async_minitest.dart`, to follow `minitest.dart`,
expecting the Flutter use of it to have been fixed to not break
on deprecation (I believe Flutter no longer breaks builds on deprecations at all).

Patch 1 is the actual change.
Patch 2+4+8 is changing all existing references to the files.
Patch 6 ignores deprecation in files still using `async_minitest.dart`.

3+5+7+9 are updating this text to make the numbers match.
Then it's just test-expectations and small tweaks from there.

Change-Id: I1b665135b5fef9b9a0c3b340ffe9daf874d0174c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373120
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-10-11 16:53:52 +00:00

255 lines
4.6 KiB
Dart

// Copyright (c) 2017, 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.
import 'dart:async';
import 'package:expect/async_helper.dart';
import 'package:expect/expect.dart';
class AsyncTracker {
int runningAsyncs = 0;
List expectedEvents;
final List actualEvents = [];
AsyncTracker(this.expectedEvents) {
asyncStart();
}
void start(String event) {
actualEvents.add("start $event");
runningAsyncs++;
}
void stop(String event) {
actualEvents.add("stop $event");
if (--runningAsyncs == 0) {
Expect.listEquals(expectedEvents, actualEvents);
asyncEnd();
}
}
void add(e) {
actualEvents.add(e);
}
}
void test1() {
var tracker = new AsyncTracker([
"start micro1",
"start foo",
"error-foo",
"start micro3",
"start micro2",
"stop micro1",
"stop foo",
"stop micro3",
"stop micro2",
]);
Future foo() async {
tracker.add("error-foo");
throw "foo";
}
tracker.start("micro1");
scheduleMicrotask(() {
tracker.start("micro2");
scheduleMicrotask(() {
tracker.stop("micro2");
});
tracker.stop("micro1");
});
tracker.start("foo");
foo().catchError((e) {
tracker.stop("foo");
});
tracker.start("micro3");
scheduleMicrotask(() {
tracker.stop("micro3");
});
}
void test2() {
var tracker = new AsyncTracker([
"start micro1",
"start bar",
"await null",
"start micro4",
"start micro2",
"stop micro1",
"error-bar",
"stop bar",
"start micro5",
"stop micro4",
"start micro3",
"stop micro2",
"stop micro5",
"stop micro3",
]);
Future bar() async {
tracker.add("await null");
await null;
tracker.add("error-bar");
throw "bar";
}
tracker.start("micro1");
scheduleMicrotask(() {
tracker.start("micro2");
scheduleMicrotask(() {
tracker.start("micro3");
scheduleMicrotask(() {
tracker.stop("micro3");
});
tracker.stop("micro2");
});
tracker.stop("micro1");
});
tracker.start("bar");
bar().catchError((e) {
tracker.stop("bar");
});
tracker.start("micro4");
scheduleMicrotask(() {
tracker.start("micro5");
scheduleMicrotask(() {
tracker.stop("micro5");
});
tracker.stop("micro4");
});
}
void test3() {
var tracker = new AsyncTracker([
"start micro1",
"start gee",
"error-gee",
"start micro3",
"start micro2",
"stop micro1",
"stop gee",
"stop micro3",
"stop micro2",
]);
Future gee() async {
tracker.add("error-gee");
return new Future.error("gee");
}
tracker.start("micro1");
scheduleMicrotask(() {
tracker.start("micro2");
scheduleMicrotask(() {
tracker.stop("micro2");
});
tracker.stop("micro1");
});
tracker.start("gee");
gee().catchError((e) {
tracker.stop("gee");
});
tracker.start("micro3");
scheduleMicrotask(() {
tracker.stop("micro3");
});
}
void test4() {
var tracker = new AsyncTracker([
"start micro1",
"start toto",
"await null",
"start micro4",
"start micro2",
"stop micro1",
"error-toto",
"start micro5",
"stop micro4",
"start micro3",
"stop micro2",
"stop toto",
"stop micro5",
"stop micro3",
]);
Future toto() async {
tracker.add("await null");
await null;
tracker.add("error-toto");
return new Future.error("toto");
}
tracker.start("micro1");
scheduleMicrotask(() {
tracker.start("micro2");
scheduleMicrotask(() {
tracker.start("micro3");
scheduleMicrotask(() {
tracker.stop("micro3");
});
tracker.stop("micro2");
});
tracker.stop("micro1");
});
tracker.start("toto");
toto().catchError((e) {
tracker.stop("toto");
});
tracker.start("micro4");
scheduleMicrotask(() {
tracker.start("micro5");
scheduleMicrotask(() {
tracker.stop("micro5");
});
tracker.stop("micro4");
});
}
void test5() {
var tracker = new AsyncTracker([
"start bar",
"start micro",
"start foo",
"throw",
"stop micro",
"stop foo",
"stop bar",
]);
Future foo() async {
tracker.add("throw");
throw "foo";
}
bar() async {
tracker.start('micro');
scheduleMicrotask(() {
tracker.stop('micro');
});
try {
tracker.start('foo');
await foo();
} catch (e) {
tracker.stop('foo');
}
tracker.stop("bar");
}
tracker.start('bar');
}
main() {
asyncStart();
test1();
test2();
test3();
test4();
asyncEnd();
}