Skip to content
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

Fix flakiness in detection of notDisposed leaks in tests. #149

Merged
merged 10 commits into from
Sep 29, 2023

Conversation

polina-c
Copy link
Contributor

@polina-c polina-c commented Sep 26, 2023

Contributes to flutter/flutter#135716

This is follow up to fix leak tracker flakiness: flutter/flutter#135394

This PR resolves false negatives, so it is breaking change.
Objects, not disposed by the end of the test, should be marked as leaks, even if they are not GCed yet.

The upgrade to this version should be handled manually, because it may result in some tests failing.

@polina-c polina-c changed the title Fix flakiness in detection notDisposed leaks in tests. Fix flakiness in detection of notDisposed leaks in tests. Sep 28, 2023
@polina-c polina-c marked this pull request as ready for review September 28, 2023 01:07
void declareAllNotDisposedAsLeaks() {
throwIfDisposed();
final notGCedAndNotDisposed = <ObjectRecord>[];
_objects.notGCed.forEach((record) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: lots of projects have lints recommending that we don't use forEach. Even if we don't have it enabled for this project, consider doing this instead:

for (final record in _objects.notGCed) {
    if (!record.isDisposed) {
      _declareNotDisposedLeak(record);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lint is enabled for this project. notGCed is not iterable though. I will check if it is easy to make it iterable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh interesting. At the very least, I don't think you need noGCedAndNotDisposed, but you could instead do:

_objects.notGCed.forEach((record) {
  if (!record.isDisposed) {
    _declareNotDisposedLeak(record);
  }
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, looks as optimizable. Added comment why I did it:

// We need this temporary storage to avoid errror 'concurrent modification during iteration'
// for internal iterables in `_objects.notGCed`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I checked: Iterable wants 27 methods to be implemented. Seems to be too heavy.

Co-authored-by: Daniel Chevalier <danchevalier@google.com>
@polina-c polina-c merged commit fa29ce4 into dart-lang:main Sep 29, 2023
2 checks passed
@polina-c polina-c deleted the fix branch September 29, 2023 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants