-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Disposes test restoration manager when accessed by bindings #176519
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
dkwingsmt
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.
LGTM. Thank you!
| import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; | ||
|
|
||
| void main() { | ||
| LeakTesting.enable(); // Enable leak testing and use default collectedLeaksReporter. |
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.
Do we really need this statement? Leak testing isn't enabled unless the LEAK_TRACKING flag is set, but this is done for a reason. All Flutter unit tests are currently configured with leak tracking in this way, and I don't see a reason why WidgetTester needs special treatment.
And if this is removed, shall we move this test to widget_tester_test.dart?
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.
I tried removing this piece of code, and I also temporarily commented out this patch by 3dabca1, but all the tests passed. So it might still need to be explicitly enabled in the code? Or did I miss something?
I found two parts in the existing code that might be related. One is the section that reads the LEAK_TRACKING flag, but this is part of flutter, and there is no similar handling under flutter_test.
flutter/packages/flutter/test/flutter_test_config.dart
Lines 15 to 29 in 255b464
| /// If true, leak tracking is enabled for all `testWidgets`. | |
| /// | |
| /// By default it is false. | |
| /// To enable the leak tracking, either pass the compilation flag | |
| /// `--dart-define LEAK_TRACKING=true` or invoke `export LEAK_TRACKING=true`. | |
| /// | |
| /// See documentation for [testWidgets] on how to except individual tests. | |
| bool _isLeakTrackingEnabled() { | |
| if (kIsWeb) { | |
| return false; | |
| } | |
| // The values can be different, one is compile time, another is run time. | |
| return const bool.fromEnvironment('LEAK_TRACKING') || | |
| (bool.tryParse(Platform.environment['LEAK_TRACKING'] ?? '') ?? false); | |
| } |
The other is the code that tests for memory leaks under flutter_test, but it uses a custom collectedLeaksReporter, which is also one of the reasons I created a new file to write the test code.
flutter/packages/flutter_test/test/widget_tester_leaks_test.dart
Lines 23 to 33 in 255b464
| void main() { | |
| LeakTesting.collectedLeaksReporter = _verifyLeaks; | |
| LeakTesting.enable(); | |
| LeakTesting.settings = LeakTesting.settings | |
| .withTrackedAll() | |
| .withTracked(allNotDisposed: true, experimentalAllNotGCed: true) | |
| .withIgnored( | |
| createdByTestHelpers: true, | |
| testHelperExceptions: <RegExp>[RegExp(RegExp.escape(memoryLeakTestsFilePath()))], | |
| ); |
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.
Yeah. I've tested locally and you're right. Let me ask around and see what's the best approach. Thank you for you detailed reply!
| // _restorationManager?.dispose(); | ||
| // _restorationManager = null; |
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.
@hgraceb Looks like you accidentally pushed a commit that comments some things out?
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.
@justinmc That was to verify the issue mentioned in #176519 (comment). I'm not sure if the results are completely consistent between local and CI. I have reverted it.
|
I've filed a PR #176992 that adds CI tasks to test leak tracking for |
victorsanni
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.
The Google testing failure is caused by this failing test in go_router.
|
@hgraceb Any thoughts on what should be done about the failing go_router test? Is that something that this PR could work around? |
|
@victorsanni @justinmc @ValentinVignal The modifications in the From my understanding, the changes in #7456 and my current modifications are equivalent; both aim to address the leakage issue with I believe the changes in Does anyone have good suggestions on how to proceed? |
testWidgets(
'Date formatting test',
(WidgetTester tester) async {},
experimentalLeakTesting: LeakTesting.settings.withIgnored(
classes: const ['TestRestorationManager'],
),
);and add a TODO to remove it when go_router's minimum flutter version includes this PR
experimentalLeakTesting: LeakTesting.settings.withIgnored(
classes: const ['TestRestorationManager'],
),What do you think of that? |
|
@ValentinVignal This sounds great, I submitted a PR: flutter/packages#10276. |
migrating test for flutter/flutter#176519 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
|
Rebasing to rerun google testing. My understanding is with flutter/packages#10276 the go_router failures should be fixed? |
@victorsanni Yes, is it still the previous error, or is there a new error now? |
Same error |
flutter/flutter@3f553f6...7b98d50 2025-11-26 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix for win32 embedder failing to send all alt key downs to the flutter app (#179097)" (flutter/flutter#179136) 2025-11-26 matt.kosarek@canonical.com Fix for win32 embedder failing to send all alt key downs to the flutter app (flutter/flutter#179097) 2025-11-26 katelovett@google.com Modernize framework lints (flutter/flutter#179089) 2025-11-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Add framework-side hitTestBehavior support to Semantics (#178817)" (flutter/flutter#179100) 2025-11-25 zhongliu88889@gmail.com Add framework-side hitTestBehavior support to Semantics (flutter/flutter#178817) 2025-11-25 engine-flutter-autoroll@skia.org Roll Packages from e019cf9 to cc3dca6 (1 revision) (flutter/flutter#179081) 2025-11-25 matt.kosarek@canonical.com Add tooltip windows to the windowing API alongside the window positioning logic (flutter/flutter#177404) 2025-11-25 matt.kosarek@canonical.com FlutterWindowsView::SendWindowMetrics now reliably sends the display_id (flutter/flutter#179053) 2025-11-25 31859944+LongCatIsLooong@users.noreply.github.com Remove semantics geometry shortcircuit (flutter/flutter#178680) 2025-11-25 bruno.leroux@gmail.com Add an assert message when OverlayEntry.remove is called twice (flutter/flutter#178163) 2025-11-25 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from pOO9Jl9HTLsEmks6y... to nzuAxCJGeJbkZCTkr... (flutter/flutter#179066) 2025-11-25 okorohelijah@google.com Dynamically set MinimumOSVersion in App.framework (flutter/flutter#178253) 2025-11-25 engine-flutter-autoroll@skia.org Roll Skia from d83c30b090f4 to 925c311f4b37 (2 revisions) (flutter/flutter#179060) 2025-11-25 fluttergithubbot@gmail.com Marks Linux build_android_host_app_with_module_aar to be unflaky (flutter/flutter#174864) 2025-11-25 fluttergithubbot@gmail.com Marks Linux_mokey complex_layout__start_up to be unflaky (flutter/flutter#174865) 2025-11-25 vegorov@google.com Manual Dart SDK roll to 3.11.0-169.0.dev (flutter/flutter#179054) 2025-11-25 katelovett@google.com Bump Dart to 3.9 (flutter/flutter#179041) 2025-11-25 engine-flutter-autoroll@skia.org Roll Skia from e298c2f93ebf to d83c30b090f4 (2 revisions) (flutter/flutter#179058) 2025-11-24 30870216+gaaclarke@users.noreply.github.com updated licenses_cpp readme (flutter/flutter#178874) 2025-11-24 engine-flutter-autoroll@skia.org Roll Skia from 43d2020be565 to e298c2f93ebf (5 revisions) (flutter/flutter#179046) 2025-11-24 116356835+AbdeMohlbi@users.noreply.github.com Refactor `_isLabel` method in `stepper.dart` to use `any` for better readablity (flutter/flutter#178909) 2025-11-24 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 5 to 6 in the all-github-actions group (flutter/flutter#179049) 2025-11-24 38378650+hgraceb@users.noreply.github.com Disposes test restoration manager when accessed by bindings (flutter/flutter#176519) 2025-11-24 bkonyi@google.com [ Widget Preview ] Always generate scaffold under `$TMP` (flutter/flutter#179039) 2025-11-24 engine-flutter-autoroll@skia.org Roll Packages from e67b6be to e019cf9 (9 revisions) (flutter/flutter#179035) 2025-11-24 1063596+reidbaker@users.noreply.github.com Update CHANGELOG.md for Flutter 3.38.3 (flutter/flutter#178935) 2025-11-24 116356835+AbdeMohlbi@users.noreply.github.com Remove unnecessary `String.valueOf` in `SettingsChannel.java` (flutter/flutter#178590) 2025-11-24 katelovett@google.com Roll pub manually, pick up flutter_lints in examples/api (flutter/flutter#179030) 2025-11-24 engine-flutter-autoroll@skia.org Roll Dart SDK from 24cc9a740bd3 to afca43095efa (1 revision) (flutter/flutter#179019) 2025-11-24 zezohassam@gmail.com Pass EXCLUDED_ARCHS from Xcode project to xcodebuild for macOS builds (flutter/flutter#176948) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC bmparr@google.com,stuartmorgan@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…176519) Fixes flutter#169119 ## Details The error caused by drag is due to the reference to `ServicesBinding.instance.restorationManager` in the `ScrollableState.saveOffset` method. https://github.com/flutter/flutter/blob/018897e3f12c5783fb025bcbd92515a69d4d5c32/packages/flutter/lib/src/widgets/scrollable.dart#L648-L656 The TestWidgetsFlutterBinding now only cleans up the `restorationManager` when `reset` is called. Therefore, we need to find an appropriate place to clean up the `restorationManager`. https://github.com/flutter/flutter/blob/018897e3f12c5783fb025bcbd92515a69d4d5c32/packages/flutter_test/lib/src/binding.dart#L239-L263 https://github.com/flutter/flutter/blob/018897e3f12c5783fb025bcbd92515a69d4d5c32/packages/flutter_test/lib/src/widget_tester.dart#L188-L193 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
…176519) Fixes flutter#169119 ## Details The error caused by drag is due to the reference to `ServicesBinding.instance.restorationManager` in the `ScrollableState.saveOffset` method. https://github.com/flutter/flutter/blob/018897e3f12c5783fb025bcbd92515a69d4d5c32/packages/flutter/lib/src/widgets/scrollable.dart#L648-L656 The TestWidgetsFlutterBinding now only cleans up the `restorationManager` when `reset` is called. Therefore, we need to find an appropriate place to clean up the `restorationManager`. https://github.com/flutter/flutter/blob/018897e3f12c5783fb025bcbd92515a69d4d5c32/packages/flutter_test/lib/src/binding.dart#L239-L263 https://github.com/flutter/flutter/blob/018897e3f12c5783fb025bcbd92515a69d4d5c32/packages/flutter_test/lib/src/widget_tester.dart#L188-L193 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This PR adds a new subshard that runs leak tracking tests on flutter/misc. This is used to address a problem faced by PR #176519, which fixes a leak in `WidgetTester` but is unable to write a unit test. I'm not certain this is the best approach so I'm open to other suggestions. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…art` (#180600) When #176519 was authored, there were no CI shards that run `flutter_test` with leak tests, and therefore the test had to be placed in a separate file. Now that #176992 has added misc leak tracking, the test case can be placed in the same file as other tests for `WidgetTester`. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Fixes #169119
Details
The error caused by drag is due to the reference to
ServicesBinding.instance.restorationManagerin theScrollableState.saveOffsetmethod.flutter/packages/flutter/lib/src/widgets/scrollable.dart
Lines 648 to 656 in 018897e
The TestWidgetsFlutterBinding now only cleans up the
restorationManagerwhenresetis called. Therefore, we need to find an appropriate place to clean up therestorationManager.flutter/packages/flutter_test/lib/src/binding.dart
Lines 239 to 263 in 018897e
flutter/packages/flutter_test/lib/src/widget_tester.dart
Lines 188 to 193 in 018897e
Pre-launch Checklist
///).