Chromium Code Reviews| Index: runtime/tests/vm/dart/isolate_unhandled_exception_test2.dart |
| =================================================================== |
| --- runtime/tests/vm/dart/isolate_unhandled_exception_test2.dart (revision 0) |
| +++ runtime/tests/vm/dart/isolate_unhandled_exception_test2.dart (revision 0) |
| @@ -0,0 +1,50 @@ |
| +import 'dart:isolate'; |
|
siva
2012/12/13 18:30:38
ditto.
|
| +import 'dart:io'; |
| + |
| +// Tests that an isolate's keeps message handling working after |
| +// throwing an unhandled exception, if it was created with an |
|
siva
2012/12/13 18:30:38
instead of created with an unhandled exception it
|
| +// unhandled exception callback that returns true (continue handling). |
| +// This test verifies that a default-named callback function is called |
| +// when no callback is specified in Isolate.spawnFunction. |
| + |
| +// Note: this test will hang if an uncaught exception isn't handled, |
| +// either by an error in the callback or it returning false. |
| + |
| +void entry() { |
| + port.receive((message, replyTo) { |
| + if (message == 'throw exception') { |
| + throw new RuntimeError('ignore this exception'); |
| + } |
| + replyTo.call('hello'); |
| + port.close(); |
| + }); |
| +} |
| + |
| +bool _unhandledExceptionCallback(IsolateUnhandledException e) { |
| + return e.source.message == 'ignore this exception'; |
| +} |
| + |
| +void main() { |
| + var isolate_port = spawnFunction(entry); |
| + |
| + // Send a message that will cause an ignorable exception to be thrown. |
| + Future f = isolate_port.call('throw exception'); |
| + f.onComplete((future) { |
| + // Exception wasn't ignored as it was supposed to be. |
| + print('failed handling exception'); |
| + exit(1); |
| + }); |
| + |
| + // Verify that isolate can still handle messages. |
| + isolate_port.call('hi').onComplete((future) { |
| + if (future.exception != null) { |
| + print('unhandled exception: ${future.exception}'); |
| + exit(1); |
| + } |
| + if (future.value != 'hello') { |
| + print('unexpected response: ${future.value}'); |
| + exit(1); |
| + } |
| + exit(0); |
| + }); |
| +} |