-
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1517bf3
-
polina-c 77e73b0
-
polina-c 8ecad8e
-
polina-c 757e3cf
Update flutter_test_config.dart
polina-c b167909
-
polina-c a9ad44c
-
polina-c 9e32356
Merge branch 'main' of github.com:dart-lang/leak_tracker into fix
polina-c 4dca891
Update _object_tracker.dart
polina-c 3a44a62
-
polina-c 88d406d
Update pkgs/leak_tracker/lib/src/leak_tracking/_object_tracker.dart
polina-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
pkgs/leak_tracker_flutter_testing/test/tests/end_to_end/failing_tests/failure_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; | ||
|
||
late String twoControllers; | ||
|
||
/// Verification for the tests happens in flutter_test_config.dart. | ||
void main() { | ||
testWidgetsWithLeakTracking( | ||
twoControllers = 'Two not disposed controllers results in two leaks.', | ||
(tester) async { | ||
// ignore: unused_local_variable | ||
final TextEditingController controller = TextEditingController(); | ||
|
||
// ignore: unused_local_variable | ||
final FocusNode focusNode = FocusNode(debugLabel: 'Test Node'); | ||
}); | ||
} |
41 changes: 41 additions & 0 deletions
41
...leak_tracker_flutter_testing/test/tests/end_to_end/failing_tests/flutter_test_config.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:leak_tracker/leak_tracker.dart'; | ||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; | ||
|
||
import 'failure_test.dart'; | ||
|
||
/// The test configuration for each test library in this directory. | ||
/// | ||
/// See https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html. | ||
Future<void> testExecutable(FutureOr<void> Function() testMain) async { | ||
Leaks? leaks; | ||
|
||
// This tear down should be set before leak tracking tear down in | ||
// order to happen after it and verify that leaks are found. | ||
tearDownAll(() async { | ||
final theLeaks = leaks; | ||
if (theLeaks == null) throw 'leaks should be detected'; | ||
|
||
expect( | ||
theLeaks.notDisposed.where((l) => l.phase == twoControllers), | ||
hasLength(2), | ||
); | ||
}); | ||
|
||
configureLeakTrackingTearDown( | ||
configureOnce: true, | ||
onLeaks: (l) => leaks = l, | ||
); | ||
|
||
setUpAll(() { | ||
LeakTracking.warnForUnsupportedPlatforms = false; | ||
}); | ||
|
||
await testMain(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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: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:
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.