Skip to content

Conversation

@hgraceb
Copy link
Member

@hgraceb hgraceb commented Oct 4, 2025

Fixes #169119

Details

The error caused by drag is due to the reference to ServicesBinding.instance.restorationManager in the ScrollableState.saveOffset method.

@protected
@override
void saveOffset(double offset) {
assert(debugIsSerializableForRestoration(offset));
_persistedScrollOffset.value = offset;
// [saveOffset] is called after a scrolling ends and it is usually not
// followed by a frame. Therefore, manually flush restoration data.
ServicesBinding.instance.restorationManager.flushData();
}

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.

@override
TestRestorationManager get restorationManager {
_restorationManager ??= createRestorationManager();
return _restorationManager!;
}
TestRestorationManager? _restorationManager;
/// Called by the test framework at the beginning of a widget test to
/// prepare the binding for the next test.
///
/// If [registerTestTextInput] returns true when this method is called,
/// the [testTextInput] is configured to simulate the keyboard.
void reset() {
_restorationManager?.dispose();
_restorationManager = null;
platformDispatcher.defaultRouteNameTestValue = '/';
resetGestureBinding();
testTextInput.reset();
if (registerTestTextInput) {
_testTextInput.register();
}
CustomSemanticsAction.resetForTests(); // ignore: invalid_use_of_visible_for_testing_member
_enableFocusManagerLifecycleAwarenessIfSupported();
}

try {
memento = await variant.setUp(value);
binding.reset(); // TODO(ianh): the binding should just do this itself in _runTest
maybeSetupLeakTrackingForTest(experimentalLeakTesting, combinedDescription);
await callback(tester);
} finally {

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.

@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 Oct 4, 2025
@hgraceb hgraceb marked this pull request as ready for review October 4, 2025 14:56
@justinmc justinmc requested a review from victorsanni October 7, 2025 22:12
@dkwingsmt dkwingsmt self-requested a review October 7, 2025 22:14
Copy link
Contributor

@dkwingsmt dkwingsmt left a 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.
Copy link
Contributor

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?

Copy link
Member Author

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.

/// 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.

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()))],
);

Copy link
Contributor

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!

Comment on lines 1070 to 1071
// _restorationManager?.dispose();
// _restorationManager = null;
Copy link
Contributor

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?

Copy link
Member Author

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.

@dkwingsmt
Copy link
Contributor

I've filed a PR #176992 that adds CI tasks to test leak tracking for flutter_test. Let's wait until that PR is decided.

Copy link
Contributor

@victorsanni victorsanni left a 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.

@justinmc
Copy link
Contributor

@hgraceb Any thoughts on what should be done about the failing go_router test? Is that something that this PR could work around?

@hgraceb
Copy link
Member Author

hgraceb commented Oct 22, 2025

@victorsanni @justinmc @ValentinVignal

The modifications in the go_router PR at #7456 are preventing the current PR from being merged.

From my understanding, the changes in #7456 and my current modifications are equivalent; both aim to address the leakage issue with TestWidgetsFlutterBinding.restorationManager after enabling leak testing. However, the changes in #7456 seem more like a temporary patch.

I believe the changes in go_router should be reverted, and after merging the current PR, the effect would remain the same as before. However, if I submit a separate PR for go_router now, both tests will fail; they will only pass if changes are made on both sides simultaneously.

Does anyone have good suggestions on how to proceed?

@ValentinVignal
Copy link
Contributor

ValentinVignal commented Oct 22, 2025

  1. Revert the unwanted changes in go_router + disable leak memory testing for those specific tests, for example using:
  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

  1. Merge this PR
  2. Remove the ignore part in go_router when the minimum version of flutter includes this fix.
experimentalLeakTesting: LeakTesting.settings.withIgnored(
      classes: const ['TestRestorationManager'],
    ),

What do you think of that?

@hgraceb
Copy link
Member Author

hgraceb commented Oct 22, 2025

@ValentinVignal This sounds great, I submitted a PR: flutter/packages#10276.

auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 6, 2025
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.
@victorsanni
Copy link
Contributor

Rebasing to rerun google testing.

My understanding is with flutter/packages#10276 the go_router failures should be fixed?

@hgraceb
Copy link
Member Author

hgraceb commented Nov 13, 2025

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?

@victorsanni
Copy link
Contributor

Yes, is it still the previous error, or is there a new error now?

Same error

@victorsanni
Copy link
Contributor

Is there more detail on the failure test? Such as which line, stack trace, or something else.

I think it's the same tests, we just need to wait for the updated go_router version to get rolled into google.

@victorsanni victorsanni self-assigned this Nov 19, 2025
@victorsanni victorsanni moved this from Todo to In Progress in Google Testing Queue Nov 22, 2025
@victorsanni victorsanni moved this from In Progress to Done in Google Testing Queue Nov 24, 2025
@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 24, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Nov 24, 2025
Merged via the queue into flutter:master with commit 35d9502 Nov 24, 2025
69 of 70 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 24, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 26, 2025
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 [email protected] Fix for win32 embedder failing to send all alt key downs to the flutter app (flutter/flutter#179097)
2025-11-26 [email protected] 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 [email protected] Add framework-side hitTestBehavior support to Semantics (flutter/flutter#178817)
2025-11-25 [email protected] Roll Packages from e019cf9 to cc3dca6 (1 revision) (flutter/flutter#179081)
2025-11-25 [email protected] Add tooltip windows to the windowing API alongside the window positioning logic (flutter/flutter#177404)
2025-11-25 [email protected] FlutterWindowsView::SendWindowMetrics now reliably sends the display_id (flutter/flutter#179053)
2025-11-25 [email protected] Remove semantics geometry shortcircuit (flutter/flutter#178680)
2025-11-25 [email protected] Add an assert message when OverlayEntry.remove is called twice (flutter/flutter#178163)
2025-11-25 [email protected] Roll Fuchsia Linux SDK from pOO9Jl9HTLsEmks6y... to nzuAxCJGeJbkZCTkr... (flutter/flutter#179066)
2025-11-25 [email protected] Dynamically set MinimumOSVersion in App.framework (flutter/flutter#178253)
2025-11-25 [email protected] Roll Skia from d83c30b090f4 to 925c311f4b37 (2 revisions) (flutter/flutter#179060)
2025-11-25 [email protected] Marks Linux build_android_host_app_with_module_aar to be unflaky (flutter/flutter#174864)
2025-11-25 [email protected] Marks Linux_mokey complex_layout__start_up to be unflaky (flutter/flutter#174865)
2025-11-25 [email protected] Manual Dart SDK roll to 3.11.0-169.0.dev (flutter/flutter#179054)
2025-11-25 [email protected] Bump Dart to 3.9 (flutter/flutter#179041)
2025-11-25 [email protected] Roll Skia from e298c2f93ebf to d83c30b090f4 (2 revisions) (flutter/flutter#179058)
2025-11-24 [email protected] updated licenses_cpp readme (flutter/flutter#178874)
2025-11-24 [email protected] Roll Skia from 43d2020be565 to e298c2f93ebf (5 revisions) (flutter/flutter#179046)
2025-11-24 [email protected] 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 [email protected] Disposes test restoration manager when accessed by bindings (flutter/flutter#176519)
2025-11-24 [email protected] [ Widget Preview ] Always generate scaffold under `$TMP` (flutter/flutter#179039)
2025-11-24 [email protected] Roll Packages from e67b6be to e019cf9 (9 revisions) (flutter/flutter#179035)
2025-11-24 [email protected] Update CHANGELOG.md for Flutter 3.38.3 (flutter/flutter#178935)
2025-11-24 [email protected] Remove unnecessary `String.valueOf` in `SettingsChannel.java‎` (flutter/flutter#178590)
2025-11-24 [email protected] Roll pub manually, pick up flutter_lints in examples/api (flutter/flutter#179030)
2025-11-24 [email protected] Roll Dart SDK from 24cc9a740bd3 to afca43095efa (1 revision) (flutter/flutter#179019)
2025-11-24 [email protected] 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 [email protected],[email protected] 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
mboetger pushed a commit to mboetger/flutter that referenced this pull request Dec 2, 2025
…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 <[email protected]>
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…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 <[email protected]>
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

Development

Successfully merging this pull request may close these issues.

Leak memory in tests when dragging a SingleChildScrollView

5 participants