OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library test; | |
6 | |
7 import 'package:expect/expect.dart'; | |
8 import 'dart:async'; | |
9 import 'dart:isolate'; | |
10 import "package:async_helper/async_helper.dart"; | |
11 | |
12 runTest() { | |
13 IsolateSink mainIsolate; | |
14 stream.listen((msg) { | |
15 mainIsolate = msg; | |
16 throw new UnsupportedError("ignore exception"); | |
17 }, onDone: () { | |
18 mainIsolate.add("received done"); | |
19 mainIsolate.close(); | |
20 }); | |
21 } | |
22 | |
23 bool globalErrorHandler(IsolateUnhandledException e) { | |
24 var source = e.source; | |
25 return source is UnsupportedError && source.message == "ignore exception"; | |
26 } | |
27 | |
28 main() { | |
29 var keepRunningBox = new MessageBox(); | |
30 // Make sure this test doesn't last longer than 2 seconds. | |
31 var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; }); | |
32 | |
33 var box = new MessageBox(); | |
34 IsolateSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler); | |
35 otherIsolate.add(box.sink); | |
36 // The previous event should have been handled entirely, but the current | |
37 // implementations don't guarantee that and might mix the done event with | |
38 // the handling of the previous event. We therefore delay the closing. | |
39 // Note: if the done is sent too early it won't lead to failing tests, but | |
40 // just won't make sure that the globalErrorHandler works. | |
41 asyncStart(); | |
42 new Timer(const Duration(milliseconds: 10), () { | |
43 otherIsolate.close(); | |
44 asyncEnd(); | |
45 }); | |
46 asyncStart(); | |
47 box.stream.single.then((msg) { | |
48 Expect.equals("received done", msg); | |
49 timer.cancel(); | |
50 keepRunningBox.stream.close(); | |
51 asyncEnd(); | |
52 }); | |
53 } | |
OLD | NEW |