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

Side by Side Diff: tests/lib_strong/async/zone_create_periodic_timer_test.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:expect/expect.dart';
6 import 'package:async_helper/async_helper.dart';
7 import 'dart:async';
8
9 main() {
10 Completer done = new Completer();
11 List events = [];
12
13 Expect.identical(Zone.ROOT, Zone.current);
14 Zone forked;
15 forked = Zone.current.fork(specification: new ZoneSpecification(
16 createPeriodicTimer: (Zone self, ZoneDelegate parent, Zone origin,
17 Duration period, f(Timer timer)) {
18 events.add("forked.createPeriodicTimer");
19 return parent.createPeriodicTimer(origin, period, (Timer timer) {
20 events.add("wrapped function ${period.inMilliseconds}");
21 f(timer);
22 });
23 }));
24
25 asyncStart();
26 int tickCount = 0;
27 forked.run(() {
28 new Timer.periodic(const Duration(milliseconds: 5),
29 (Timer timer) {
30 events.add("periodic Timer $tickCount");
31 Expect.identical(forked, Zone.current);
32 tickCount++;
33 if (tickCount == 4) {
34 timer.cancel();
35 // Allow some time in case the cancel didn't work.
36 new Timer(const Duration(milliseconds: 20), done.complete);
37 }
38 });
39 });
40
41 Expect.identical(Zone.ROOT, Zone.current);
42 events.add("after createPeriodicTimer");
43
44 done.future.whenComplete(() {
45 Expect.listEquals(
46 [ "forked.createPeriodicTimer", "after createPeriodicTimer",
47 "wrapped function 5", "periodic Timer 0",
48 "wrapped function 5", "periodic Timer 1",
49 "wrapped function 5", "periodic Timer 2",
50 "wrapped function 5", "periodic Timer 3" ],
51 events);
52 asyncEnd();
53 });
54 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/zone_bind_test.dart ('k') | tests/lib_strong/async/zone_create_timer2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698