Migrated test block 167 to Dart 2.0.

No manual work required for this block.

BUG=
R=jcollins@google.com

Review-Url: https://codereview.chromium.org/2993213003 .
This commit is contained in:
Ben Konyi 2017-08-17 12:42:30 -07:00
parent 8692f618f6
commit 55612ef10c
25 changed files with 65 additions and 633 deletions

View file

@ -182,7 +182,6 @@ async/stream_periodic4_test: RuntimeError # Timer interface not supported; Issue
async/stream_periodic5_test: RuntimeError # Timer interface not supported; Issue 7728.
async/stream_periodic6_test: RuntimeError # Timer interface not supported; Issue 7728.
async/run_zoned7_test: RuntimeError # Timer interface not supported: Issue 7728.
async/catch_errors22_test: RuntimeError # Timer interface not supported: Issue 7728.
async/timer_isActive_test: RuntimeError # Timer interface not supported: Issue 7728.
async/zone_empty_description2_test: RuntimeError # Timer interface not supported: Issue 7728.
async/zone_create_timer2_test: RuntimeError # Timer interface not supported: Issue 7728.
@ -191,10 +190,6 @@ async/catch_errors12_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors13_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors14_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors15_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors18_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors19_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors20_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors28_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors8_test: Fail # Timer interface not supported: Issue 7728.
async/run_zoned8_test: Fail # Timer interface not supported: Issue 7728.
async/zone_bind_test: Fail # Timer interface not supported: Issue 7728.

View file

@ -0,0 +1,55 @@
library catch_errors;
import 'dart:async';
Stream catchErrors(void body()) {
StreamController controller;
bool onError(e, st) {
controller.add(e);
return true;
}
void onListen() {
runZoned(body, onError: onError);
}
controller = new StreamController(onListen: onListen);
return controller.stream;
}
runZonedScheduleMicrotask(body(),
{void onScheduleMicrotask(void callback()), Function onError}) {
if (onScheduleMicrotask == null) {
return runZoned(body, onError: onError);
}
HandleUncaughtErrorHandler errorHandler;
if (onError != null) {
errorHandler = (Zone self, ZoneDelegate parent, Zone zone, error,
StackTrace stackTrace) {
try {
return self.parent.runUnary(onError, error);
} catch (e, s) {
if (identical(e, error)) {
return parent.handleUncaughtError(zone, error, stackTrace);
} else {
return parent.handleUncaughtError(zone, e, s);
}
}
};
}
ScheduleMicrotaskHandler asyncHandler;
if (onScheduleMicrotask != null) {
asyncHandler = (Zone self, ZoneDelegate parent, Zone zone, f()) {
self.parent.runUnary(onScheduleMicrotask, () => zone.runGuarded(f));
};
}
ZoneSpecification specification = new ZoneSpecification(
handleUncaughtError: errorHandler, scheduleMicrotask: asyncHandler);
Zone zone = Zone.current.fork(specification: specification);
if (onError != null) {
return zone.runGuarded(body);
} else {
return zone.run(body);
}
}

View file

@ -0,0 +1,10 @@
# 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.
[ $compiler == dart2js && $runtime == jsshell ]
async/catch_errors22_test: RuntimeError # Timer interface not supported: Issue 7728.
async/catch_errors18_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors19_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors20_test: Fail # Timer interface not supported: Issue 7728.
async/catch_errors28_test: Fail # Timer interface not supported: Issue 7728.

View file

@ -1,42 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
Stream stream =
new Stream.periodic(const Duration(milliseconds: 20), (x) => x);
// Test that errors of periodic streams are caught.
catchErrors(() {
var subscription;
subscription = stream.listen((x) {
if (x == 5) {
events.add("cancel");
subscription.cancel();
done.complete(true);
return;
}
events.add(x);
});
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([0, 1, 2, 3, 4, "cancel"], events);
asyncEnd();
});
});
}

View file

@ -1,42 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
Stream stream =
new Stream.periodic(const Duration(milliseconds: 20), (x) => x);
// Test that asynchronous callbacks in the done-handler of streams (here
// the `catchErrors`-stream) keep a zone alive.
catchErrors(() {
var subscription;
subscription = stream.take(5).listen((x) {
events.add(x);
}, onDone: () {
new Future.delayed(const Duration(milliseconds: 30), () {
events.add(499);
done.complete(true);
});
});
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([0, 1, 2, 3, 4, 499], events);
asyncEnd();
});
});
}

View file

@ -1,45 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
// Test that nested stream (from `catchErrors`) that is delayed by a future
// is waited for.
catchErrors(() {
catchErrors(() {
new Future.error(499);
new Future.delayed(const Duration(milliseconds: 20), () {
events.add(42);
done.complete(true);
});
}).listen(events.add, onDone: () {
events.add("done");
});
throw "foo";
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([
"outer: foo",
499,
42,
], events);
asyncEnd();
});
});
}

View file

@ -1,55 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
var controller = new StreamController();
// Test that stream errors, as a result of bad user-code (`map`) are correctly
// caught by `catchErrors`. Note that the values are added outside both
// `catchErrors`, but since the `listen` happens in the most nested
// `catchErrors` it is caught there.
catchErrors(() {
catchErrors(() {
controller.stream.map((x) {
throw x;
}).listen((x) {
// Should not happen.
events.add("bad: $x");
});
}).listen((x) {
events.add("caught: $x");
if (x == 4) done.complete(true);
}, onDone: () {
Expect.fail("Unexpected callback");
});
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([
"caught: 1",
"caught: 2",
"caught: 3",
"caught: 4",
], events);
asyncEnd();
});
});
[1, 2, 3, 4].forEach(controller.add);
controller.close();
}

View file

@ -1,48 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
var events = [];
bool onDoneWasCalled = false;
var controller = new StreamController();
// Test that streams that are never closed keep the `catchError` alive.
catchErrors(() {
catchErrors(() {
controller.stream.map((x) {
throw x;
}).listen((x) {
// Should not happen.
events.add("bad: $x");
});
}).listen((x) {
events.add("caught: $x");
}, onDone: () {
events.add("done");
});
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
onDoneWasCalled = true;
});
[1, 2, 3, 4].forEach(controller.add);
new Timer(const Duration(milliseconds: 20), () {
Expect.isFalse(onDoneWasCalled);
Expect.listEquals([
"caught: 1",
"caught: 2",
"caught: 3",
"caught: 4",
], events);
asyncEnd();
});
}

View file

@ -1,79 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
StreamController controller;
Stream stream;
// Test that errors are not traversing zone boundaries.
// Note that the first listener of `asBroadcastStream` determines in which
// zone the subscription lives.
catchErrors(() {
catchErrors(() {
controller = new StreamController();
// Assign to "global" `stream`.
stream = controller.stream.map((x) {
events.add("map $x");
return x + 100;
}).transform(
new StreamTransformer.fromHandlers(handleError: (e, st, sink) {
sink.add("error $e");
})).asBroadcastStream();
// Listen to `stream` in the inner zone.
stream.listen((x) {
events.add("stream $x");
});
})
.listen((x) {
events.add(x);
})
.asFuture()
.then((_) {
Expect.fail("Unexpected callback");
});
// Listen to `stream` in the outer zone.
stream.listen((x) {
events.add("stream2 $x");
});
// Feed the controller from the outer zone.
controller.add(1);
// `addError` does not count as zone-traversal. It should be caught by
// the inner error handler.
controller.addError("inner error");
new Future.error("caught by outer");
controller.close();
}).listen((x) {
events.add("outer: $x");
if (x == "caught by outer") done.complete(true);
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([
"map 1",
"stream 101",
"stream2 101",
"stream error inner error",
"stream2 error inner error",
"outer: caught by outer",
], events);
asyncEnd();
});
});
}

View file

@ -1,79 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
StreamController controller;
Stream stream;
// Test that the first listen on a `asBroadcastStream` determines the
// zone the subscription lives in. In this case the outer listen happens first
// and the error reaches `handleError`.
catchErrors(() {
catchErrors(() {
controller = new StreamController();
// Assign to the "global" `stream`.
stream = controller.stream.map((x) {
events.add("map $x");
return x + 100;
}).transform(
new StreamTransformer.fromHandlers(handleError: (e, st, sink) {
sink.add("error $e");
})).asBroadcastStream();
// Listen to the `stream` in the inner zone (but wait in a microtask).
scheduleMicrotask(() {
stream.listen((x) {
events.add("stream $x");
if (x == "error 2") done.complete(true);
});
});
})
.listen((x) {
events.add(x);
})
.asFuture()
.then((_) {
Expect.fail("Unexpected callback");
});
// Listen to `stream` from the outer zone.
stream.listen((x) {
events.add("stream2 $x");
});
// Feed the controller, but wait in a microtask.
scheduleMicrotask(() {
controller.add(1);
controller.addError(2);
controller.close();
});
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to complete.
Timer.run(() {
Expect.listEquals([
"map 1",
"stream2 101",
"stream 101",
"stream2 error 2",
"stream error 2",
], events);
asyncEnd();
});
});
}

View file

@ -1,36 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
StreamController controller;
// Test multiple subscribers of an asBroadcastStream inside the same
// `catchErrors`.
catchErrors(() {
var stream = new Stream.fromIterable([1, 2]).asBroadcastStream();
stream.listen(events.add);
stream.listen(events.add);
done.complete(stream.listen(null).asFuture());
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([1, 1, 2, 2], events);
asyncEnd();
});
});
}

View file

@ -1,74 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
StreamController controller;
Stream stream;
// Test `StreamController.broadcast` streams.
catchErrors(() {
catchErrors(() {
controller = new StreamController.broadcast();
// Listen to the stream from the inner zone.
controller.stream.map((x) {
events.add("map $x");
return x + 100;
}).transform(
new StreamTransformer.fromHandlers(handleError: (e, st, sink) {
sink.add("error $e");
})).listen((x) {
events.add("stream $x");
});
})
.listen((x) {
events.add(x);
})
.asFuture()
.then((_) {
Expect.fail("Unexpected callback");
});
// Listen to the stream from the outer zone.
controller.stream.listen((x) {
events.add("stream2 $x");
}, onError: (x) {
events.add("stream2 error $x");
});
// Feed the controller.
controller.add(1);
controller.addError("inner stream");
new Future.error("outer error");
controller.close();
}).listen((x) {
events.add("outer: $x");
if (x == "outer error") done.complete(true);
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([
"map 1",
"stream 101",
"stream2 1",
"stream error inner stream",
"stream2 error inner stream",
"outer: outer error",
], events);
asyncEnd();
});
});
}

View file

@ -1,79 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
StreamController controller;
Stream stream;
// Test that streams live in the zone they have been listened too.
// It doesn't matter how many zone-boundaries the stream traverses. What
// counts is the zone where `listen` was invoked.
catchErrors(() {
catchErrors(() {
controller = new StreamController();
// Assignment to "global" `stream`.
stream = controller.stream.map((x) {
events.add("map $x");
return x + 100;
}).asBroadcastStream();
// Consume stream in the nested zone.
stream.transform(
new StreamTransformer.fromHandlers(handleError: (e, st, sink) {
sink.add("error $e");
})).listen((x) {
events.add("stream $x");
});
// Feed the controller in the nested zone.
scheduleMicrotask(() {
controller.add(1);
controller.addError(2);
controller.close();
new Future.error("done");
});
})
.listen((x) {
events.add("listen: $x");
if (x == "done") done.complete(true);
})
.asFuture()
.then((_) {
Expect.fail("Unexpected callback");
});
// Listen to stream in outer zone.
stream.listen((x) {
events.add("stream2 $x");
});
}).listen((x) {
events.add("outer: $x");
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([
"map 1",
"stream 101",
"stream2 101",
"stream error 2",
"listen: done",
"outer: 2",
], events);
asyncEnd();
});
});
}

View file

@ -1,49 +0,0 @@
// Copyright (c) 2013, 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 'package:async_helper/async_helper.dart';
import "package:expect/expect.dart";
import 'dart:async';
import 'catch_errors.dart';
main() {
asyncStart();
Completer done = new Completer();
var events = [];
// Test that periodic Timers are handled correctly by `catchErrors`.
catchErrors(() {
int counter = 0;
new Timer.periodic(const Duration(milliseconds: 50), (timer) {
if (counter == 5) {
timer.cancel();
done.complete(true);
}
counter++;
events.add(counter);
});
}).listen((x) {
events.add(x);
}, onDone: () {
Expect.fail("Unexpected callback");
});
done.future.whenComplete(() {
// Give handlers time to run.
Timer.run(() {
Expect.listEquals([
"main exit",
1,
2,
3,
4,
5,
6,
], events);
asyncEnd();
});
});
events.add("main exit");
}