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

Unified Diff: tests/isolate/browser/typed_data_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/browser/compute_this_script_browser_test.dart ('k') | tests/isolate/count_stream_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/browser/typed_data_message_test.dart
diff --git a/tests/isolate/browser/typed_data_message_test.dart b/tests/isolate/browser/typed_data_message_test.dart
index 38e7815c0598f6cada81be946835efdbe5584a1e..e4483903b00d4fac6eb8fdeddb796281f2adcae3 100644
--- a/tests/isolate/browser/typed_data_message_test.dart
+++ b/tests/isolate/browser/typed_data_message_test.dart
@@ -56,42 +56,55 @@ void VerifyObject(int index, var actual) {
expect(actual.length, expected.length);
}
-pingPong() {
+pingPong(SendPort initialReplyTo) {
+ var port = new ReceivePort();
+ initialReplyTo.send(port.sendPort);
initializeList();
int count = 0;
- port.receive((var message, SendPort replyTo) {
- if (message == -1) {
+ port.listen((var message) {
+ var data = message[0];
+ SendPort replyTo = message[1];
+ if (data == -1) {
port.close();
replyTo.send(count, null);
} else {
// Check if the received object is correct.
if (count < elements.length) {
- VerifyObject(count, message);
+ VerifyObject(count, data);
}
// Bounce the received object back so that the sender
// can make sure that the object matches.
- replyTo.send(message, null);
+ replyTo.send(data, null);
count++;
}
});
}
+Future sendReceive(SendPort port, msg) {
+ ReceivePort response = new ReceivePort();
+ port.send([msg, response.sendPort]);
+ return response.first;
+}
+
main() {
initializeList();
test("send objects and receive them back", () {
- SendPort remote = spawnFunction(pingPong);
- // Send objects and receive them back.
- for (int i = 0; i < elements.length; i++) {
- var sentObject = elements[i];
- var idx = i;
- remote.call(sentObject).then(expectAsync1((var receivedObject) {
- VerifyObject(idx, receivedObject);
- }));
- }
+ ReceivePort response = new ReceivePort();
+ Isolate.spawn(pingPong, response.sendPort);
+ response.first.then((SendPort remote) {
+ // Send objects and receive them back.
+ for (int i = 0; i < elements.length; i++) {
+ var sentObject = elements[i];
+ var idx = i;
+ sendReceive(remote, sentObject).then(expectAsync1((var receivedObject) {
+ VerifyObject(idx, receivedObject);
+ }));
+ }
- // Shutdown the MessageServer.
- remote.call(-1).then(expectAsync1((int message) {
- expect(message, elements.length);
- }));
+ // Shutdown the MessageServer.
+ sendReceive(remote, -1).then(expectAsync1((int message) {
+ expect(message, elements.length);
+ }));
+ });
});
}
« no previous file with comments | « tests/isolate/browser/compute_this_script_browser_test.dart ('k') | tests/isolate/count_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698