Skip to content

Commit

Permalink
Enable leak tracking (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Jan 16, 2024
1 parent d696f6e commit 229124a
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 17 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ jobs:
matrix:
channel:
- master
- dev
- beta

steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
with:
fetch-depth: 2

- uses: subosito/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ android/
ios/
macos/
.packages
build

# Remove the following pattern if you wish to check in your lock file
pubspec.lock
Expand Down
2 changes: 2 additions & 0 deletions packages/provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
# The version is `any` because it is defined by Flutter SDK.
leak_tracker: any
mockito: ^5.0.0
test: ^1.15.5
11 changes: 11 additions & 0 deletions packages/provider/test/flutter_test_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

FutureOr<void> testExecutable(FutureOr<void> Function() testMain) {
LeakTesting.enable();
LeakTesting.settings = LeakTesting.settings
.withIgnored(allNotGCed: true, createdByTestHelpers: true);

return testMain();
}
23 changes: 19 additions & 4 deletions packages/provider/test/null_safe/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ void main() {
});

testWidgets('.value', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider.value(
value: ValueNotifier(0),
value: notifier,
builder: (context, child) {
context.watch<ValueNotifier<int>>();
return child!;
Expand All @@ -41,7 +44,12 @@ void main() {
testWidgets('default', (tester) async {
await tester.pumpWidget(
ListenableProvider(
create: (_) => ValueNotifier(0),
create: (_) {
final valueNotifier = ValueNotifier(0);
addTearDown(valueNotifier.dispose);

return valueNotifier;
},
builder: (context, child) {
context.watch<ValueNotifier<int>>();
return child!;
Expand All @@ -54,9 +62,12 @@ void main() {
});

testWidgets('.value', (tester) async {
final valueNotifier = ValueNotifier(0);
addTearDown(valueNotifier.dispose);

await tester.pumpWidget(
ListenableProvider.value(
value: ValueNotifier(0),
value: valueNotifier,
builder: (context, child) {
context.watch<ValueNotifier<int>>();
return child!;
Expand Down Expand Up @@ -326,7 +337,11 @@ void main() {
MultiProvider(
providers: [
ListenableProvider(
create: (_) => ValueNotifier(0),
create: (_) {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);
return notifier;
},
),
],
builder: (context, child) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void main() {
group('ChangeNotifierProvider', () {
testWidgets('value', (tester) async {
final myNotifier = ValueNotifier<int>(0);
addTearDown(myNotifier.dispose);

await tester.pumpWidget(
MultiProvider(
Expand Down
25 changes: 23 additions & 2 deletions packages/provider/test/null_safe/context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void main() {
group('context.watch<T?>', () {
testWidgets('can watch T', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>>.value(
Expand Down Expand Up @@ -36,6 +37,7 @@ void main() {

testWidgets('can watch T?', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
Expand Down Expand Up @@ -98,6 +100,8 @@ void main() {
expect(find.text(''), findsOneWidget);

final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
value: notifier,
Expand All @@ -117,6 +121,7 @@ void main() {
group('context.watch<T>', () {
testWidgets('can watch T?', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
Expand Down Expand Up @@ -175,6 +180,7 @@ void main() {
group('context.select<T?>', () {
testWidgets('can watch T', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>>.value(
Expand Down Expand Up @@ -203,6 +209,7 @@ void main() {

testWidgets('can watch T?', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
Expand Down Expand Up @@ -268,6 +275,8 @@ void main() {
expect(find.text(''), findsOneWidget);

final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
value: notifier,
Expand All @@ -287,6 +296,7 @@ void main() {
group('context.select<T>', () {
testWidgets('can watch T?', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
Expand Down Expand Up @@ -315,6 +325,7 @@ void main() {

testWidgets('can watch T', (tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>>.value(
Expand Down Expand Up @@ -386,9 +397,12 @@ void main() {
},
);

final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
ChangeNotifierProvider<ValueNotifier<int>?>.value(
value: ValueNotifier(0),
value: notifier,
child: child,
),
);
Expand Down Expand Up @@ -691,10 +705,13 @@ void main() {
testWidgets("don't call old selectors if the child rebuilds individually",
(tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

var buildCount = 0;
final selectedNotifier = ValueNotifier(0);
addTearDown(selectedNotifier.dispose);
final selector =
MockSelector.identity<ValueNotifier<int>>(ValueNotifier(0));
MockSelector.identity<ValueNotifier<int>>(selectedNotifier);
final child = Builder(builder: (c) {
buildCount++;
c.select<ValueNotifier<int>, ValueNotifier<int>>(selector);
Expand Down Expand Up @@ -1057,6 +1074,7 @@ void main() {

testWidgets('context.select deeply compares maps', (tester) async {
final notifier = ValueNotifier(<int, int>{});
addTearDown(notifier.dispose);

var buildCount = 0;
final selector = MockSelector.identity<Map<int, int>>({});
Expand Down Expand Up @@ -1100,6 +1118,7 @@ void main() {

testWidgets('context.select deeply compares lists', (tester) async {
final notifier = ValueNotifier(<int>[]);
addTearDown(notifier.dispose);

var buildCount = 0;
final selector = MockSelector.identity<List<int>>([]);
Expand Down Expand Up @@ -1142,6 +1161,7 @@ void main() {

testWidgets('context.select deeply compares iterables', (tester) async {
final notifier = ValueNotifier<Iterable<int>>(<int>[]);
addTearDown(notifier.dispose);

var buildCount = 0;
final selector = MockSelector.identity<Iterable<int>>({});
Expand Down Expand Up @@ -1184,6 +1204,7 @@ void main() {

testWidgets('context.select deeply compares sets', (tester) async {
final notifier = ValueNotifier<Set<int>>(<int>{});
addTearDown(notifier.dispose);

var buildCount = 0;
final selector = MockSelector.identity<Set<int>>({});
Expand Down
1 change: 1 addition & 0 deletions packages/provider/test/null_safe/devtool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {

testWidgets('calls postEvent whenever a provider is updated', (tester) async {
final notifier = ValueNotifier(42);
addTearDown(notifier.dispose);

await tester.pumpWidget(
MultiProvider(
Expand Down
17 changes: 15 additions & 2 deletions packages/provider/test/null_safe/inherited_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ void main() {
'Provider.of(listen: false) outside of build works when it loads a provider',
(tester) async {
final notifier = ValueNotifier(42);
addTearDown(notifier.dispose);

await tester.pumpWidget(
MultiProvider(
providers: [
Expand Down Expand Up @@ -329,9 +331,10 @@ void main() {
testWidgets(
'builder receives the current value and updates independently from `update`',
(tester) async {
final child = Container();

final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

final child = Container();
final builder = TransitionBuilderMock((c, child) {
final notifier = Provider.of<ValueNotifier<int>>(c);
return Text(
Expand Down Expand Up @@ -365,6 +368,8 @@ void main() {
final child = Container();

final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

final builder = TransitionBuilderMock((c, child) {
return const Text('foo', textDirection: TextDirection.ltr);
});
Expand Down Expand Up @@ -392,6 +397,8 @@ void main() {
final child = Container();

final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

final builder = TransitionBuilderMock((c, child) {
return const Text('foo', textDirection: TextDirection.ltr);
});
Expand Down Expand Up @@ -1663,6 +1670,7 @@ DeferredInheritedProvider<int, int>(controller: 42, value: 24)'''),
},
);
final controller = ValueNotifier<int>(0);
addTearDown(controller.dispose);

await tester.pumpWidget(
DeferredInheritedProvider<ValueNotifier<int>, int>.value(
Expand Down Expand Up @@ -1714,6 +1722,7 @@ DeferredInheritedProvider<int, int>(controller: 42, value: 24)'''),
},
);
final controller = ValueNotifier<int>(0);
addTearDown(controller.dispose);

await tester.pumpWidget(
DeferredInheritedProvider<ValueNotifier<int>, int>.value(
Expand All @@ -1729,6 +1738,7 @@ DeferredInheritedProvider<int, int>(controller: 42, value: 24)'''),
DeferredStartListeningMock<ValueNotifier<int>, int>();
when(startListening2(any, any, any, any)).thenReturn(() {});
final controller2 = ValueNotifier<int>(0);
addTearDown(controller2.dispose);

await tester.pumpWidget(
DeferredInheritedProvider<ValueNotifier<int>, int>.value(
Expand Down Expand Up @@ -1849,6 +1859,7 @@ DeferredInheritedProvider<int, int>(controller: 42, value: 24)'''),
DeferredStartListeningMock<ValueNotifier<int>, int>();
when(startListening(any, any, any, any)).thenReturn(() {});
final controller = ValueNotifier<int>(0);
addTearDown(controller.dispose);

await tester.pumpWidget(
DeferredInheritedProvider<ValueNotifier<int>, int>.value(
Expand Down Expand Up @@ -1882,6 +1893,7 @@ DeferredInheritedProvider<int, int>(controller: 42, value: 24)'''),
},
);
final controller = ValueNotifier<int>(0);
addTearDown(controller.dispose);

await tester.pumpWidget(
DeferredInheritedProvider<ValueNotifier<int>, int>.value(
Expand All @@ -1905,6 +1917,7 @@ DeferredInheritedProvider<int, int>(controller: 42, value: 24)'''),
},
);
final controller2 = ValueNotifier<int>(1);
addTearDown(controller2.dispose);

await tester.pumpWidget(
DeferredInheritedProvider<ValueNotifier<int>, int>.value(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void main() {
testWidgets('works with MultiProvider', (tester) async {
final key = GlobalKey();
final listenable = ChangeNotifier();
addTearDown(listenable.dispose);

await tester.pumpWidget(
MultiProvider(
Expand All @@ -30,6 +31,7 @@ void main() {
(tester) async {
final key = GlobalKey();
final notifier = ValueNotifier(0)..addListener(() {});
addTearDown(notifier.dispose);

await tester.pumpWidget(
ListenableProvider(
Expand Down Expand Up @@ -258,6 +260,8 @@ void main() {
when(builder(any)).thenReturn(Container());

var listenable = ChangeNotifier();
addTearDown(listenable.dispose);

Widget build() {
return ListenableProvider.value(
value: listenable,
Expand All @@ -276,6 +280,7 @@ void main() {

final previousNotifier = listenable;
listenable = ChangeNotifier();
addTearDown(listenable.dispose);

await tester.pumpWidget(build());

Expand Down Expand Up @@ -349,6 +354,8 @@ void main() {

testWidgets('notifylistener rebuilds descendants', (tester) async {
final listenable = ChangeNotifier();
addTearDown(listenable.dispose);

final keyChild = GlobalKey();
final builder = BuilderMock();
when(builder(any)).thenReturn(Container());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ void main() {
testWidgets('rebuilds dependendents when listeners are called',
(tester) async {
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);

await tester.pumpWidget(
MultiProvider(
providers: [
Expand Down Expand Up @@ -117,6 +119,7 @@ void main() {
testWidgets('disposes of created value', (tester) async {
final dispose = DisposeMock<ValueNotifier<int>>();
final notifier = ValueNotifier(0);
addTearDown(notifier.dispose);
final key = GlobalKey();

await tester.pumpWidget(
Expand Down
Loading

0 comments on commit 229124a

Please sign in to comment.