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

Side by Side Diff: tests/isolate/global_error_handler_stream2_test.dart

Issue 12720015: Fix and improve isolate tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/isolate/global_error_handler_stream_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 runTest() { 10 runTest() {
11 IsolateSink mainIsolate; 11 IsolateSink mainIsolate;
12 stream.listen((msg) { 12 stream.listen((msg) {
13 mainIsolate = msg; 13 mainIsolate = msg;
14 throw new RuntimeError("ignore exception"); 14 throw new RuntimeError("ignore exception");
15 }, onDone: () { 15 }, onDone: () {
16 mainIsolate.add("received done"); 16 mainIsolate.add("received done");
17 mainIsolate.close(); 17 mainIsolate.close();
18 }); 18 });
19 } 19 }
20 20
21 bool globalErrorHandler(IsolateUnhandledException e) { 21 bool globalErrorHandler(IsolateUnhandledException e) {
22 var source = e.source; 22 var source = e.source;
23 if (source is AsyncError) { 23 if (source is AsyncError) {
24 source = source.error; 24 source = source.error;
25 } 25 }
26 return source is RuntimeError && source.message == "ignore exception"; 26 return source is RuntimeError && source.message == "ignore exception";
27 } 27 }
28 28
29 main() { 29 main() {
30 var keepRunningBox = new MessageBox();
30 // Make sure this test doesn't last longer than 2 seconds. 31 // Make sure this test doesn't last longer than 2 seconds.
31 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); 32 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; });
32 33
33 var box = new MessageBox(); 34 var box = new MessageBox();
34 IsolateSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler); 35 IsolateSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler);
35 otherIsolate.add(box.sink); 36 otherIsolate.add(box.sink);
36 otherIsolate.close(); 37 // The previous event should have been handled entirely, but the current
38 // implementations don't guarantee that and might mix the done event with
39 // the handling of the previous event. We therefore delay the closing.
40 // Note: if the done is sent too early it won't lead to failing tests, but
41 // just won't make sure that the globalErrorHandler works.
42 new Timer(const Duration(milliseconds: 10), otherIsolate.close);
37 box.stream.single.then((msg) { 43 box.stream.single.then((msg) {
38 Expect.equals("received done", msg); 44 Expect.equals("received done", msg);
39 timer.cancel(); 45 timer.cancel();
46 keepRunningBox.stream.close();
40 }); 47 });
41 } 48 }
OLDNEW
« no previous file with comments | « no previous file | tests/isolate/global_error_handler_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698