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

Side by Side Diff: tests/isolate/start_paused_test.dart

Issue 163523003: Add 'startPaused' option to Isolate.spawn*. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 10 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
« no previous file with comments | « tests/isolate/isolate.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 library start_paused_test;
6
7 import "dart:isolate";
8 import "package:expect/expect.dart";
9 import "package:async_helper/async_helper.dart";
10
11 void isomain(SendPort p) {
12 p.send("DONE");
13 }
14
15 void notyet(_) {
16 throw "NOT YET";
17 }
18
19 void main() {
20 asyncStart();
21 test1();
22 test2();
23 asyncEnd();
24 }
25
26 void test1() {
27 // Test that a paused isolate doesn't send events.
28 // We start two isolates, one paused and one not.
29 // The unpaused one must send an event, after which
30 // we resume that paused isolate, and expect the second event.
31 // This is not a guaranteed test, since it can succeede even if the
32 // paused isolate isn't really paused.
33 // However, it must never fail, since that would mean that a paused
34 // isolate sends a message.
35 asyncStart();
36 RawReceivePort p1 = new RawReceivePort(notyet);
37 Isolate.spawn(isomain, p1.sendPort, paused: true)
38 .then((isolate) {
39 RawReceivePort p2;
40 p2 = new RawReceivePort((x) {
41 Expect.equals("DONE", x);
42 p2.close();
43 p1.handler = (x) {
44 Expect.equals("DONE", x);
45 p1.close();
46 asyncEnd();
47 };
48 isolate.resume(isolate.pauseCapability);
49 });
50 Isolate.spawn(isomain, p2.sendPort);
51 });
52 }
53
54 void test2() {
55 // Test that a paused isolate doesn't send events.
56 // Like the test above, except that we change the pause capability
57 // of the paused isolate by pausing it using another capability and
58 // then resuming the initial pause. This must not cause it to send
59 // a message before the second pause is resumed as well.
60 asyncStart();
61 RawReceivePort p1 = new RawReceivePort(notyet);
62 Isolate.spawn(isomain, p1.sendPort, paused: true)
63 .then((isolate) {
64 RawReceivePort p2;
65 Capability c2 = new Capability();
66 // Switch to another pause capability.
67 isolate.pause(c2);
68 isolate.resume(isolate.pauseCapability);
69 p2 = new RawReceivePort((x) {
70 Expect.equals("DONE", x);
71 p2.close();
72 p1.handler = (x) {
73 Expect.equals("DONE", x);
74 p1.close();
75 asyncEnd();
76 };
77 isolate.resume(c2);
78 });
79 Isolate.spawn(isomain, p2.sendPort);
80 });
81 }
OLDNEW
« no previous file with comments | « tests/isolate/isolate.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698