-
Notifications
You must be signed in to change notification settings - Fork 28
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
#2398. Make asyncStart/End() safe in LibTest/async #2416
Conversation
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.
LGTM!
I still think this style is somewhat misleading:
main() {
asyncStart();
test(Zone.current);
test(Zone.current.fork());
asyncEnd();
}
(because we aren't pairing up the two asyncStart
/asyncEnd
invocations with each other at run time), but I think we have been digging deep enough into this topic to be happy about what we've got now. ;-)
I'll await further input.
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.
LGTM, thanks.
@eernstg Could you elaborate on what's wrong with the example you give? Is it from an actual test? |
It's from LibTest/async/Zone/createPeriodicTimer_A01_t01.dart. I don't think there is an actual problem, and certainly no need to make changes to working tests. However, it did take some time for me to get used to the idea that we have a syntactic structure that seems to imply pairing (a parenthesis structure), but the actual run-time behavior has a different structure. In particular, here is the example that I mentioned: main() {
asyncStart();
test(Zone.current);
test(Zone.current.fork());
asyncEnd();
} When this test is executed, the Next, Next, If So it's crucial that Also, this means that the In summary, there's no way the nice symmetry of having both I tend to think that it would be more readable if we had an In any case, I certainly don't want to block things at this point. So I'll land this PR now, and then we can always continue the discussion and make changes if there is a need for that. |
@eernstg thank you! Indeed, with the pair of test(...) {
future.then(() {
...
asyncEnd();
});
}
main() {
asyncStart(2);
test(...);
test(...);
} This should really prevent from failures caused by a threads race. Probably it doesn't make sense to update all of the tests right now because we don't have this problem in practice, but, at least, now we have understanding how such test should be written |
Agreed! This whole discussion has certainly improved my understanding of how to properly use |
2023-12-07 sgrekhov22@gmail.com Fixes dart-lang/co19#2413. Add missing expected compile-time errors for CFE (dart-lang/co19#2418) 2023-12-07 sgrekhov22@gmail.com dart-lang/co19#2119. Run dart formatter on LibTest/async tests (dart-lang/co19#2417) 2023-12-06 sgrekhov22@gmail.com dart-lang/co19#2398. Make asyncStart/End() safe in LibTest/async (dart-lang/co19#2416) 2023-12-06 sgrekhov22@gmail.com Fixes dart-lang/co19#2355. Add more typed_date.setRange() tests (dart-lang/co19#2412) 2023-12-06 sgrekhov22@gmail.com dart-lang/co19#2404. Small code-style improvements and description update (dart-lang/co19#2414) 2023-12-04 sgrekhov22@gmail.com dart-lang/co19#2004. Add deferred libraries tests according to the changed spec (dart-lang/co19#2411) 2023-12-04 sgrekhov22@gmail.com Fixes dart-lang/co19#2383. Add more constant evaluation tests (dart-lang/co19#2396) Change-Id: I15e0d681538fa0f2a311f74d1930fad7270b81a0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340561 Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Erik Ernst <eernst@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
The most part of the changes here is to add
asyncStart/End()
guards to tests likeWithout these new guards if, for some reasons,
asyncStart/End()
pair in the first invocation oftest()
will be completed before the call of the secondtest()
then the test will fail (invocation ofasyncStart()
afterunit-test-suite-success
throws) or may be successfully finished on web (if the driver will be fast enough)There are also a little bit of code formatting, but not much. I'm going to run dart fromatter on these tests after merge of this PR