| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 test; | 5 library test; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 | 10 |
| 11 runTest() { | 11 runTest() { |
| 12 SendPort mainIsolate; | 12 SendPort mainIsolate; |
| 13 bool isFirst = true; | 13 bool isFirst = true; |
| 14 port.receive((msg, replyTo) { | 14 port.receive((msg, replyTo) { |
| 15 if (isFirst) { | 15 if (isFirst) { |
| 16 mainIsolate = msg; | 16 mainIsolate = msg; |
| 17 isFirst = false; | 17 isFirst = false; |
| 18 throw new RuntimeError("ignore exception"); | 18 throw new UnsupportedError("ignore exception"); |
| 19 } | 19 } |
| 20 Expect.equals("message 2", msg); | 20 Expect.equals("message 2", msg); |
| 21 mainIsolate.send("received"); | 21 mainIsolate.send("received"); |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 bool globalErrorHandler(IsolateUnhandledException e) { | 25 bool globalErrorHandler(IsolateUnhandledException e) { |
| 26 return e.source is RuntimeError && e.source.message == "ignore exception"; | 26 return e.source is UnsupportedError && e.source.message == "ignore exception"; |
| 27 } | 27 } |
| 28 | 28 |
| 29 main() { | 29 main() { |
| 30 // Make sure this test doesn't last longer than 2 seconds. | 30 // Make sure this test doesn't last longer than 2 seconds. |
| 31 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); | 31 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); |
| 32 | 32 |
| 33 var port = new ReceivePort(); | 33 var port = new ReceivePort(); |
| 34 SendPort otherIsolate = spawnFunction(runTest, globalErrorHandler); | 34 SendPort otherIsolate = spawnFunction(runTest, globalErrorHandler); |
| 35 otherIsolate.send(port.toSendPort()); | 35 otherIsolate.send(port.toSendPort()); |
| 36 otherIsolate.send("message 2"); | 36 otherIsolate.send("message 2"); |
| 37 port.receive((msg, replyPort) { | 37 port.receive((msg, replyPort) { |
| 38 Expect.equals("received", msg); | 38 Expect.equals("received", msg); |
| 39 port.close(); | 39 port.close(); |
| 40 timer.cancel(); | 40 timer.cancel(); |
| 41 }); | 41 }); |
| 42 } | 42 } |
| OLD | NEW |