Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: tests/language/await_for_test.dart

Issue 2739703002: Revert "Add test for cancel-future being awaited after an `await for`." (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/await_for_test.dart
diff --git a/tests/language/await_for_test.dart b/tests/language/await_for_test.dart
index 3e5c0c24920f2de36f9c1c7b6f445b27466a8120..8c6f18e94e548d25057acdfeaef70c9a56c0e247 100644
--- a/tests/language/await_for_test.dart
+++ b/tests/language/await_for_test.dart
@@ -7,12 +7,11 @@ import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
class Trace {
- String trace;
- Trace(this.trace);
- void record(x) {
+ String trace = "";
+ record(x) {
trace += x.toString();
}
- String toString() => trace;
+ toString() => trace;
}
@@ -20,115 +19,68 @@ Stream makeMeAStream() {
return timedCounter(5);
}
+Trace t1 = new Trace();
-consumeOne(trace) async {
+consumeOne() async {
// Equivalent to await for (x in makeMeAStream()) { ... }
var s = makeMeAStream();
var it = new StreamIterator(s);
while (await it.moveNext()) {
var x = it.current;
- trace.record(x);
+ t1.record(x);
}
- trace.record("X");
+ t1.record("X");
}
+Trace t2 = new Trace();
-consumeTwo(trace) async {
+consumeTwo() async {
await for (var x in makeMeAStream()) {
- trace.record(x);
+ t2.record(x);
}
- trace.record("Y");
+ t2.record("Y");
}
+Trace t3 = new Trace();
-consumeNested(trace) async {
+consumeNested() async {
await for (var x in makeMeAStream()) {
- trace.record(x);
+ t3.record(x);
await for (var y in makeMeAStream()) {
- trace.record(y);
+ t3.record(y);
}
- trace.record("|");
+ t3.record("|");
}
- trace.record("Z");
+ t3.record("Z");
}
-consumeSomeOfInfinite(trace) async {
+Trace t4 = new Trace();
+
+consumeSomeOfInfinite() async {
int i = 0;
await for (var x in infiniteStream()) {
i++;
if (i > 10) break;
- trace.record(x);
+ t4.record(x);
}
- trace.record("U");
-}
-
-const String cancelError =
- "ERROR: Error in future returned by .cancel() must be caught";
-
-/// Creates a stream that yields integers forever, but throws when canceled.
-///
-/// The thrown error should end up in the future returned by `cancel`.
-Stream<int> errorOnCancelStream(int n) async* {
- try {
- while (true) yield n++;
- } finally {
- throw cancelError;
- }
-}
-
-
-// Sanity-check that the errorOnCancelStream behaves as expected.
-testErrorOnCancel() {
- var stream = errorOnCancelStream(0);
- var subscription = stream.listen(null);
- return subscription.cancel().then((_) {
- Expect.fail("Cancel future did not contain error");
- }, onError: (e) {
- Expect.equals(cancelError, e);
- });
-}
-
-testCancelAwaited() async {
- return runZoned(() async {
- var stream = errorOnCancelStream(0);
- try {
- var n = 0;
- await for (var x in stream) {
- Expect.equals(n++, x);
- if (x == 5) break;
- }
- Expect.fail("Didn't await the cancel future.");
- } on String catch (e) {
- Expect.equals(cancelError, e);
- }
- }, onError: (e) {
- // Catch the error if it's uncaught.
- if (cancelError == e) {
- Expect.fail("Error in cancel is considered uncaught");
- }
- throw e;
- });
+ t4.record("U");
}
main() {
- Trace t1 = new Trace("T1:");
- var f1 = consumeOne(t1);
-
- Trace t2 = new Trace("T2:");
- var f2 = consumeTwo(t2);
-
- Trace t3 = new Trace("T3:");
- var f3 = consumeNested(t3);
-
- Trace t4 = new Trace("T4:");
- var f4 = consumeSomeOfInfinite(t4);
-
- var f5 = testErrorOnCancel();
-
- var f6 = testCancelAwaited();
+ var f1 = consumeOne();
+ t1.record("T1:");
+
+ var f2 = consumeTwo();
+ t2.record("T2:");
+
+ var f3 = consumeNested();
+ t3.record("T3:");
+
+ var f4 = consumeSomeOfInfinite();
+ t4.record("T4:");
asyncStart();
- Future.wait([f1, f2, f3, f4, f5, f6]).then((_) {
+ Future.wait([f1, f2, f3, f4]).then((_) {
Expect.equals("T1:12345X", t1.toString());
Expect.equals("T2:12345Y", t2.toString());
Expect.equals("T3:112345|212345|312345|412345|512345|Z", t3.toString());
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698