-
Notifications
You must be signed in to change notification settings - Fork 29
#2933. Add tests for Stream.multi constructor.
#2935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Are there tests for the |
sgrekhov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. PTAL.
Are there tests for the
MultiStreamControllerAPI? Which is the normalStreamControllerAPI plusaddSync,addErrorSyncandcloseSync, which allows adding events synchronously (afterlistenhas returned, not paused, and if there are no prior events still enqueued).
I'm working on these tests now and will add them later in a separate PR.
BTW could you, please, help me to understand if the following test is correct or not?
main() {
asyncStart(2);
int counter = 1;
var stream = Stream<int>.multi((controller) {
for (;;counter++) {
controller.add(counter);
if (counter % 5 == 0) {
controller.close();
counter++;
return;
}
}
});
int i = 1;
stream.listen((v) {
print(v);
Expect.equals(v, i++);
}, onDone: () {
Expect.equals(6, i);
asyncEnd();
});
int j = 6;
stream.listen((v) {
print(v);
Expect.equals(v, j++);
}, onDone: () {
Expect.equals(11, j);
asyncEnd();
});
}The test works for me but it's unclear for me why. The output is
unittest-suite-wait-for-done
1
6
2
7
3
8
4
9
5
10
unittest-suite-success
Seems that the controller syncronously sends data to the first listener and then to the second. Is this expected? If yes, what's the difference between add and addSync?
eernstg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a couple of comments.
sgrekhov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. PTAL.
That question would probably fit just fine as an issue on the SDK repository with the label |
It's not wrong. I wouldn't depend on the interleaving always being what it is. The It's guaranteed that the streams will emit those events, because all events are computed synchronously. The scheduling gives the interleaving you see. I would not guarantee any specific interleaving of separate event sources. We can guarantee that the next enqueued event will be delivered in a later microtask, but not precisely which later microtask. So, working as intended. |
2024-10-18 sgrekhov22@gmail.com Fixes dart-lang/co19#2938. Remove string literals identity check (dart-lang/co19#2939) 2024-10-17 sgrekhov22@gmail.com dart-lang/co19#2933. Add MultiStreamController tests. Part 2. (dart-lang/co19#2937) 2024-10-17 sgrekhov22@gmail.com dart-lang/co19#2930. Add MultiStreamController tests. Part 1. (dart-lang/co19#2936) 2024-10-16 sgrekhov22@gmail.com dart-lang/co19#2933. Add tests for `Stream.multi` constructor. (dart-lang/co19#2935) 2024-10-15 sgrekhov22@gmail.com dart-lang/co19#2933. Add tests for `Stream.error` and `Stream.value` constructors. (dart-lang/co19#2934) 2024-10-14 sgrekhov22@gmail.com Fixes dart-lang/co19#2930. Fix failing Stream tests. (dart-lang/co19#2932) Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try Change-Id: Ib7d939f6edaf72a344e75c473e564923d3c811cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390702 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
No description provided.