Skip to content

Conversation

@lrhn
Copy link
Contributor

@lrhn lrhn commented Mar 11, 2025

Current implementation runs timers and microtask callbacks in the root zone. That assumes that the top-level scheduleMicrotask or Timer constructors have been used, which have so far wrapped the callback with runCallbackGuarded before calling the zone implementation.
That means that doing zone.scheduleMicrotask directly would not ensure that the microtask was run in the correct zone. If a run handler throws, it wouldn't be caught.

This change makes the realAsyncZone do whatever the root zone would do if its ZoneDelegate got called with the intended zone and arguments. That should be consistent with the current behavior, and be compatible with incoming bug-fixes to the platform Zone behavior.

Prepares Flutter for landing https://dart-review.googlesource.com/c/sdk/+/406961
which is currently blocked (so this indirectly blocks fixing the dart-lang/sdk#59913).

Adds test to check that the callbacks do run in the expected zone. Otherwise all existing tests should keep running, and they should keep doing so when the Dart CL lands. Currently that CL only breaks one test, the dev/automated_tests/test_smoke_test/fail_test_on_exception_after_test.dart test which threw the error-after-test in the root zone instead of the test zone. This change fixes that.

(This is a copy of #162731 merged to head, to see if the goldens change is spurious. It seems so.)

lrhn added 3 commits March 11, 2025 16:37
Current implementation runs timers and microtask callbacks in the root zone.
That assumes that the top-level `scheduleMicrotask` or `Timer` constructors
have been used, which have so far wrapped the callback with `runCallbackGuarded`
before calling the zone implementation.
That means that doing `zone.scheduleMicrotask` directly would not ensure
that the microtask was run in the correct zone. If a `run` handler throws,
it wouldn't be caught.

This change makes the `realAsyncZone` do whatever the root zone would
do if its `ZoneDelegate` got called with the intended zone and arguments.
That should be consistent with the current behavior, and be compatible
with changes to the platform `Zone` behavior.
@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. labels Mar 11, 2025
@lrhn
Copy link
Contributor Author

lrhn commented Mar 12, 2025

Does seem that there are no golden issues. PTAL either this or #162731 to get the Dart SDK CL unblocked.

@Piinks
Copy link
Contributor

Piinks commented Apr 30, 2025

Since #162731 was a copy of this, and it was merged, I am going to close this PR since it looks like we're all set here. Thanks for contributing!
Let me know if this is not a dupe, and we can reopen it.

@Piinks Piinks closed this Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants