-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
void declareAllNotDisposedAsLeaks() { | ||
throwIfDisposed(); | ||
final notGCedAndNotDisposed = <ObjectRecord>[]; | ||
_objects.notGCed.forEach((record) { |
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.
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);
}
}
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 lint is enabled for this project. notGCed is not iterable though. I will check if it is easy to make it iterable.
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.
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);
}
});
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.
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`.
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.
And I checked: Iterable wants 27 methods to be implemented. Seems to be too heavy.
Co-authored-by: Daniel Chevalier <[email protected]>
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.