Skip to content

Define testWidgetsWithLeakTracking. - #125063

Merged
polina-c merged 95 commits into
flutter:masterfrom
polina-c:twwlt
May 4, 2023
Merged

polina-c merged 95 commits into
flutter:masterfrom
polina-c:twwlt

Conversation

@polina-c

@polina-c polina-c commented Apr 18, 2023 •

Copy link
Copy Markdown
Contributor

contributes to: flutter/devtools#3951

@flutter-dashboard flutter-dashboard Bot added p: material_ui material_ui package in flutter/packages framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Apr 18, 2023
Comment thread packages/flutter/test/foundation/leak_tracking.dart Outdated
Comment on lines +80 to +83
if (!_webWarningPrinted) {
_webWarningPrinted = true;
debugPrint('Leak tracking is not supported on web platform.');
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@polina-c polina-c Apr 19, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made actionable.

Comment thread packages/flutter/test/material/tooltip_test.dart Outdated
Comment on lines +1026 to +1028
// Using [testWidgets] instead of [testWidgetsWithLeakTracking] because
// [tooltipState] is hold after disposal by the test
// and thus is not garbage collected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me question that turning on leak tracking by default is actually feasible. This is a fairly common pattern. If people are confronted with a non-actionable leak warnings every time they obtain a state in a test, they'll likely get frustrated with these warnings and stop paying attention to the legitimate ones.

@polina-c polina-c Apr 19, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.
Added allowlist for such leaks.
Having leak tracking on by default will force people to comment the allow list entries explaining what is going on, that I think, is good thing as it builds intuition about leak prone situations and shared meaning of what to expect from garbage collector.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this a bit offline but unfortunately without @goderbauer - this test is a little strange in that it's poking at a disposed object after the object has been disposed.

I think a reasonable API would be to somehow add that object as "intentionally leaked", e.g. tester.ignoredLeakedObject(tooltipState). WDYT @goderbauer ?

@goderbauer goderbauer May 2, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is a little strange in that it's poking at a disposed object after the object has been disposed.

For my own understanding: If you'd remove the last expect(tooltipState.ensureTooltipVisible(), false); from the test, the leak tracker would not complain because there is no interaction with a disposed object? Or would holding the disposed tooltipState in that variable still constitute a leak? I believe, doing the latter is somewhat common...

I think a reasonable API would be to somehow add that object as "intentionally leaked",

Again, I think to answer this question we need to know how common this situation is, i.e. how often would test authors get confused about a false leak warning? For that, I would check how often this situation happens in our current test code base...

@polina-c polina-c May 2, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I collected some statistics. Out of 142 tests, there is just 1 that holds state after disposal.
Yes, it counts as a leak, because an object is expected to be GCed soon after disposal.

Looking forward to discuss details on a meeting.

@flutter-dashboard flutter-dashboard Bot added a: animation Animation APIs a: text input Entering text in a text field or keyboard related problems f: gestures flutter/packages/flutter/gestures repository. labels May 2, 2023
@polina-c
polina-c marked this pull request as ready for review May 2, 2023 23:09

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after comments are addressed.

Comment thread packages/flutter/test/foundation/leak_tracking.dart Outdated
Comment thread packages/flutter/test/foundation/leak_tracking.dart Outdated
Comment thread packages/flutter/test/foundation/leak_tracking.dart Outdated
Comment thread packages/flutter/test/foundation/leak_tracking.dart Outdated
Comment thread packages/flutter/test/foundation/leak_tracking_test.dart Outdated
Comment thread packages/flutter/test/foundation/leak_tracking.dart Outdated
///
/// The objects are referenced by hash codes and can duplicate with low probability.
@visibleForTesting
class WeakSet {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is also unused now and should have been removed?

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: animation Animation APIs a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants