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

Side by Side Diff: tests/html/async_test.dart

Issue 13308002: Add a test for timers in child isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 library async_test;
2
3 import '../../pkg/unittest/lib/unittest.dart';
4 import '../../pkg/unittest/lib/html_config.dart';
5
6 import 'dart:async';
7 import 'dart:isolate';
8 import 'dart:html';
9
10 oneshotTimerIsolate() {
11 port.receive((msg, replyTo) {
12 expect(msg, 'START');
13 new Timer(const Duration(milliseconds: 10), () {
14 replyTo.send('DONE');
15 });
16 });
17 }
18
19 periodicTimerIsolate() {
20 port.receive((msg, replyTo) {
21 expect(msg, 'START');
22 int counter = 0;
23 new Timer.periodic(const Duration(milliseconds: 10), (timer) {
24 if (counter == 3) {
25 counter = 1024;
26 timer.cancel();
27 // Wait some more time to be sure callback won't be invoked any
28 // more.
29 new Timer(const Duration(milliseconds: 30), () {
30 replyTo.send('DONE');
31 });
32 }
33 assert(counter < 3);
34 counter++;
35 });
36 });
37 }
38
39 cancellingIsolate() {
40 port.receive((msg, replyTo) {
41 expect(msg, 'START');
42 final oneshot = new Timer(const Duration(milliseconds: 30), () {
43 fail('Should never be invoked');
44 });
45 bool shot = false;
46 var periodic;
47 periodic = new Timer.periodic(const Duration(milliseconds: 10), (timer) {
48 expect(shot, isFalse);
49 shot = true;
50 expect(timer, same(periodic));
51 periodic.cancel();
52 oneshot.cancel();
53 // Wait some more time to be sure callbacks won't be invoked any
54 // more.
55 new Timer(const Duration(milliseconds: 50), () {
56 replyTo.send('DONE');
57 });
58 });
59 });
60 }
61
62 main() {
63 useHtmlConfiguration();
64
65 test('one shot timer in pure isolate', () {
66 expect(spawnFunction(oneshotTimerIsolate).call('START'),
67 completion('DONE'));
68 });
69 test('periodic timer in pure isolate', () {
70 expect(spawnFunction(oneshotTimerIsolate).call('START'),
vsm 2013/04/01 15:27:32 Looks like you lost this fix (should be periodicTi
Anton Muhin 2013/04/02 11:51:22 Thank you, bad merge.
71 completion('DONE'));
72 });
73 test('cancellation in pure isolate', () {
74 expect(spawnFunction(cancellingIsolate).call('START'),
75 completion('DONE'));
76 });
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698