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

Unified Diff: tests/isolate/cross_isolate_message_test.dart

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/isolate/cross_isolate_message_stream_test.dart ('k') | tests/isolate/global_error_handler2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/cross_isolate_message_test.dart
diff --git a/tests/isolate/cross_isolate_message_test.dart b/tests/isolate/cross_isolate_message_test.dart
index 41b2c7ae1141acbb18790d675802b2f933e68d3a..00874d09e97a4f6e232bdb7dd641ac8f056ed77a 100644
--- a/tests/isolate/cross_isolate_message_test.dart
+++ b/tests/isolate/cross_isolate_message_test.dart
@@ -9,51 +9,49 @@ library CrossIsolateMessageTest;
import 'dart:isolate';
import '../../pkg/unittest/lib/unittest.dart';
-void crossIsolate1() {
- port.receive((msg, replyTo) {
- SendPort otherIsolate = msg;
- ReceivePort receivePort = new ReceivePort();
- receivePort.receive((msg, replyTo) {
- otherIsolate.send(msg + 58, null); // 100.
- receivePort.close();
- });
- replyTo.send(['ready', receivePort.toSendPort()]);
- port.close();
+/*
+ * Everything starts in the main-isolate (in the main-method).
+ * The main isolate spawns two isolates: isolate1 (with entry point
+ * 'crossIsolate1') and isolate2 (with entry point 'crossIsolate2').
+ *
+ * The main isolate creates two isolates, isolate1 and isolate2.
+ * The second isolate is created with a send-port being listened on by
+ * isolate1. A message is passed along this from isolate2 to isolate1.
+ * Isolate1 then sends the result back to the main isolate for final checking.
+ */
+
+void crossIsolate1(SendPort mainIsolate) {
+ ReceivePort local = new ReceivePort();
+ mainIsolate.send(["ready1", local.sendPort]);
+ local.first.then((msg) {
+ // Message from crossIsolate2
+ expect(msg[0], "fromIsolate2");
+ mainIsolate.send(["fromIsolate1", msg[1] + 58]); // 100.
});
}
-// crossIsolate2 is nearly the same as crossIsolate1, but contains a
-// different constant.
-void crossIsolate2() {
- port.receive((msg, replyTo) {
- SendPort mainIsolate = msg;
- ReceivePort receivePort = new ReceivePort();
- receivePort.receive((msg, replyTo) {
- mainIsolate.send(msg + 399, null); // 499.
- receivePort.close();
- });
- replyTo.send(['ready', receivePort.toSendPort()]);
- port.close();
- });
+void crossIsolate2(SendPort toIsolate1) {
+ toIsolate1.send(["fromIsolate2", 42]);
}
main() {
- test("share port, and send message cross isolates ", () {
- SendPort port1 = spawnFunction(crossIsolate1);
- SendPort port2 = spawnFunction(crossIsolate2);
- // Create a new receive port and send it to isolate2.
- ReceivePort myPort = new ReceivePort();
- port2.call(myPort.toSendPort()).then(expectAsync1((msg) {
- expect(msg[0], "ready");
- // Send port of isolate2 to isolate1.
- port1.call(msg[1]).then(expectAsync1((msg) {
- expect(msg[0], "ready");
- myPort.receive(expectAsync2((msg, replyTo) {
- expect(msg, 499);
- myPort.close();
- }));
- msg[1].send(42, null);
- }));
- }));
+ test("send message cross isolates ", () {
+ ReceivePort fromIsolate1 = new ReceivePort();
+ Isolate.spawn(crossIsolate1, fromIsolate1.sendPort);
+ var done = expectAsync0((){});
+ fromIsolate1.listen((msg) {
+ switch (msg[0]) {
+ case "ready1":
+ SendPort toIsolate1 = msg[1];
+ Isolate.spawn(crossIsolate2, toIsolate1);
+ break;
+ case "fromIsolate1":
+ expect(msg[1], 100);
+ fromIsolate1.close();
+ break;
+ default:
+ fail("unreachable! Tag: ${msg[0]}");
+ }
+ }, onDone: done);
});
}
« no previous file with comments | « tests/isolate/cross_isolate_message_stream_test.dart ('k') | tests/isolate/global_error_handler2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698