| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library start_paused_test; | 5 library start_paused_test; |
| 6 | 6 |
| 7 import "dart:isolate"; | 7 import "dart:isolate"; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Test that a paused isolate doesn't send events. | 27 // Test that a paused isolate doesn't send events. |
| 28 // We start two isolates, one paused and one not. | 28 // We start two isolates, one paused and one not. |
| 29 // The unpaused one must send an event, after which | 29 // The unpaused one must send an event, after which |
| 30 // we resume that paused isolate, and expect the second event. | 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 | 31 // This is not a guaranteed test, since it can succeede even if the |
| 32 // paused isolate isn't really paused. | 32 // paused isolate isn't really paused. |
| 33 // However, it must never fail, since that would mean that a paused | 33 // However, it must never fail, since that would mean that a paused |
| 34 // isolate sends a message. | 34 // isolate sends a message. |
| 35 asyncStart(); | 35 asyncStart(); |
| 36 RawReceivePort p1 = new RawReceivePort(notyet); | 36 RawReceivePort p1 = new RawReceivePort(notyet); |
| 37 Isolate.spawn(isomain, p1.sendPort, paused: true) | 37 Isolate.spawn(isomain, p1.sendPort, paused: true).then((isolate) { |
| 38 .then((isolate) { | |
| 39 RawReceivePort p2; | 38 RawReceivePort p2; |
| 40 p2 = new RawReceivePort((x) { | 39 p2 = new RawReceivePort((x) { |
| 41 Expect.equals("DONE", x); | 40 Expect.equals("DONE", x); |
| 42 p2.close(); | 41 p2.close(); |
| 43 p1.handler = (x) { | 42 p1.handler = (x) { |
| 44 Expect.equals("DONE", x); | 43 Expect.equals("DONE", x); |
| 45 p1.close(); | 44 p1.close(); |
| 46 asyncEnd(); | 45 asyncEnd(); |
| 47 }; | 46 }; |
| 48 isolate.resume(isolate.pauseCapability); | 47 isolate.resume(isolate.pauseCapability); |
| 49 }); | 48 }); |
| 50 Isolate.spawn(isomain, p2.sendPort); | 49 Isolate.spawn(isomain, p2.sendPort); |
| 51 }); | 50 }); |
| 52 } | 51 } |
| 53 | 52 |
| 54 void test2() { | 53 void test2() { |
| 55 // Test that a paused isolate doesn't send events. | 54 // Test that a paused isolate doesn't send events. |
| 56 // Like the test above, except that we change the pause capability | 55 // Like the test above, except that we change the pause capability |
| 57 // of the paused isolate by pausing it using another capability and | 56 // of the paused isolate by pausing it using another capability and |
| 58 // then resuming the initial pause. This must not cause it to send | 57 // then resuming the initial pause. This must not cause it to send |
| 59 // a message before the second pause is resumed as well. | 58 // a message before the second pause is resumed as well. |
| 60 asyncStart(); | 59 asyncStart(); |
| 61 RawReceivePort p1 = new RawReceivePort(notyet); | 60 RawReceivePort p1 = new RawReceivePort(notyet); |
| 62 Isolate.spawn(isomain, p1.sendPort, paused: true) | 61 Isolate.spawn(isomain, p1.sendPort, paused: true).then((isolate) { |
| 63 .then((isolate) { | |
| 64 RawReceivePort p2; | 62 RawReceivePort p2; |
| 65 Capability c2 = new Capability(); | 63 Capability c2 = new Capability(); |
| 66 // Switch to another pause capability. | 64 // Switch to another pause capability. |
| 67 isolate.pause(c2); | 65 isolate.pause(c2); |
| 68 isolate.resume(isolate.pauseCapability); | 66 isolate.resume(isolate.pauseCapability); |
| 69 p2 = new RawReceivePort((x) { | 67 p2 = new RawReceivePort((x) { |
| 70 Expect.equals("DONE", x); | 68 Expect.equals("DONE", x); |
| 71 p2.close(); | 69 p2.close(); |
| 72 p1.handler = (x) { | 70 p1.handler = (x) { |
| 73 Expect.equals("DONE", x); | 71 Expect.equals("DONE", x); |
| 74 p1.close(); | 72 p1.close(); |
| 75 asyncEnd(); | 73 asyncEnd(); |
| 76 }; | 74 }; |
| 77 isolate.resume(c2); | 75 isolate.resume(c2); |
| 78 }); | 76 }); |
| 79 Isolate.spawn(isomain, p2.sendPort); | 77 Isolate.spawn(isomain, p2.sendPort); |
| 80 }); | 78 }); |
| 81 } | 79 } |
| OLD | NEW |