Created
August 14, 2013 21:53
-
-
Save alxhub/6236045 to your computer and use it in GitHub Desktop.
An isolated test showing failure of runZonedExperimental on a checked mode exception.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:unittest/unittest.dart'; | |
import 'dart:async'; | |
main() { | |
/* | |
* In checked mode: Crashes with: 'dart:async/zone.dart': Failed assertion: line 115 pos 12: '! _children.isEmpty' is not true. | |
* In unchecked mode: hangs because runZonedExperimental() swallows the completion of the future | |
* (due to the fact that an error appears on the Stream, I believe). | |
*/ | |
test('Isolated runZonedExperimental failure test.', () { | |
var input = new Stream.fromFuture(new Future.error(new ArgumentError('foo'))); | |
var controller = new StreamController<Future>.broadcast(sync: true); | |
var sub; | |
// Bad type annotation: <String>. Should be <dynamic>. | |
var completer = new Completer<String>.sync(); | |
var outputController = new StreamController(); | |
// Publish a tracking record for this request (synchronously). | |
controller.add(completer.future); | |
void done(v, [e]) { | |
// Don't complete twice. | |
if (completer.isCompleted) { | |
return; | |
} | |
if (v != null) { | |
completer.complete(v); | |
} else { | |
completer.complete(e); | |
} | |
} | |
input.first.catchError((e) { | |
runZonedExperimental(() { | |
outputController.addError(e); | |
}, onDone: () => done(null, e)); | |
}); | |
var output = outputController.stream; | |
controller.stream.first.then(expectAsync1((onFirstResponse) { | |
onFirstResponse.then(expectAsync1((error) { | |
expect(error, new isInstanceOf<ArgumentError>()); | |
})); | |
})); | |
output.listen((_) { | |
// Never called. | |
}).onError(expectAsync1((error) { | |
expect(error, new isInstanceOf<ArgumentError>()); | |
})); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment