Fix and improve isolate tests.

Review URL: https://codereview.chromium.org//12720015

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20229 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
floitsch@google.com 2013-03-19 18:29:20 +00:00
parent 8a85df8ca3
commit b1de75561a
2 changed files with 9 additions and 2 deletions

View file

@ -27,15 +27,22 @@ bool globalErrorHandler(IsolateUnhandledException e) {
}
main() {
var keepRunningBox = new MessageBox();
// Make sure this test doesn't last longer than 2 seconds.
var timer = new Timer(const Duration(seconds: 2), () { throw "failed"; });
var box = new MessageBox();
IsolateSink otherIsolate = streamSpawnFunction(runTest, globalErrorHandler);
otherIsolate.add(box.sink);
otherIsolate.close();
// The previous event should have been handled entirely, but the current
// implementations don't guarantee that and might mix the done event with
// the handling of the previous event. We therefore delay the closing.
// Note: if the done is sent too early it won't lead to failing tests, but
// just won't make sure that the globalErrorHandler works.
new Timer(const Duration(milliseconds: 10), otherIsolate.close);
box.stream.single.then((msg) {
Expect.equals("received done", msg);
timer.cancel();
keepRunningBox.stream.close();
});
}

View file

@ -21,7 +21,7 @@ void runFunctions() {
void startTest(StreamSink finishSink) {
firstFunction = () { throw new RuntimeError("ignore exception"); };
finishFunction = () { finishSink.add("done"); finishPort.close(); };
finishFunction = () { finishSink.add("done"); finishSink.close(); };
new Timer(Duration.ZERO, runFunctions);
}