Unverified Commit fdf05c90 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Fix leaks in tests. (#142677)

parent e91f530b
...@@ -14,6 +14,12 @@ void main() { ...@@ -14,6 +14,12 @@ void main() {
late ui.Image testImage; late ui.Image testImage;
ui.Image cloneImage() {
final ui.Image clone = testImage.clone();
addTearDown(clone.dispose);
return clone;
}
setUpAll(() async { setUpAll(() async {
testImage = await createTestImage(width: 10, height: 10); testImage = await createTestImage(width: 10, height: 10);
}); });
...@@ -34,10 +40,7 @@ void main() { ...@@ -34,10 +40,7 @@ void main() {
return Scrollable.of(find.byType(TestWidget).evaluate().first).position; return Scrollable.of(find.byType(TestWidget).evaluate().first).position;
} }
testWidgets('ScrollAwareImageProvider does not delay if widget is not in scrollable', testWidgets('ScrollAwareImageProvider does not delay if widget is not in scrollable', (WidgetTester tester) async {
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
final GlobalKey<TestWidgetState> key = GlobalKey<TestWidgetState>(); final GlobalKey<TestWidgetState> key = GlobalKey<TestWidgetState>();
await tester.pumpWidget(TestWidget(key)); await tester.pumpWidget(TestWidget(key));
...@@ -65,10 +68,7 @@ void main() { ...@@ -65,10 +68,7 @@ void main() {
expect(imageCache.currentSize, 1); expect(imageCache.currentSize, 1);
}); });
testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is not scrolling', testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is not scrolling', (WidgetTester tester) async {
// TODO(polina-c): make sure images are disposed, https://github.com/flutter/flutter/issues/141388 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
final GlobalKey<TestWidgetState> key = GlobalKey<TestWidgetState>(); final GlobalKey<TestWidgetState> key = GlobalKey<TestWidgetState>();
await tester.pumpWidget(Directionality( await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -105,10 +105,7 @@ void main() { ...@@ -105,10 +105,7 @@ void main() {
expect(findPhysics<RecordingPhysics>(tester).velocities, <double>[0]); expect(findPhysics<RecordingPhysics>(tester).velocities, <double>[0]);
}); });
testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is scrolling slowly', testWidgets('ScrollAwareImageProvider does not delay if in scrollable that is scrolling slowly', (WidgetTester tester) async {
// TODO(polina-c): make sure images are disposed, https://github.com/flutter/flutter/issues/141388 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
final List<GlobalKey<TestWidgetState>> keys = <GlobalKey<TestWidgetState>>[]; final List<GlobalKey<TestWidgetState>> keys = <GlobalKey<TestWidgetState>>[];
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
addTearDown(scrollController.dispose); addTearDown(scrollController.dispose);
...@@ -167,10 +164,7 @@ void main() { ...@@ -167,10 +164,7 @@ void main() {
expect(imageCache.currentSize, 1); expect(imageCache.currentSize, 1);
}); });
testWidgets('ScrollAwareImageProvider delays if in scrollable that is scrolling fast', testWidgets('ScrollAwareImageProvider delays if in scrollable that is scrolling fast', (WidgetTester tester) async {
// TODO(polina-c): make sure images are disposed, https://github.com/flutter/flutter/issues/141388 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
final List<GlobalKey<TestWidgetState>> keys = <GlobalKey<TestWidgetState>>[]; final List<GlobalKey<TestWidgetState>> keys = <GlobalKey<TestWidgetState>>[];
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
addTearDown(scrollController.dispose); addTearDown(scrollController.dispose);
...@@ -239,10 +233,7 @@ void main() { ...@@ -239,10 +233,7 @@ void main() {
expect(imageCache.currentSize, 1); expect(imageCache.currentSize, 1);
}); });
testWidgets('ScrollAwareImageProvider delays if in scrollable that is scrolling fast and fizzles if disposed', testWidgets('ScrollAwareImageProvider delays if in scrollable that is scrolling fast and fizzles if disposed', (WidgetTester tester) async {
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
final List<GlobalKey<TestWidgetState>> keys = <GlobalKey<TestWidgetState>>[]; final List<GlobalKey<TestWidgetState>> keys = <GlobalKey<TestWidgetState>>[];
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
addTearDown(scrollController.dispose); addTearDown(scrollController.dispose);
...@@ -261,7 +252,7 @@ void main() { ...@@ -261,7 +252,7 @@ void main() {
final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState!); final DisposableBuildContext context = DisposableBuildContext(keys.last.currentState!);
addTearDown(context.dispose); addTearDown(context.dispose);
final TestImageProvider testImageProvider = TestImageProvider(testImage.clone()); final TestImageProvider testImageProvider = TestImageProvider(cloneImage());
final ScrollAwareImageProvider<TestImageProvider> imageProvider = ScrollAwareImageProvider<TestImageProvider>( final ScrollAwareImageProvider<TestImageProvider> imageProvider = ScrollAwareImageProvider<TestImageProvider>(
context: context, context: context,
imageProvider: testImageProvider, imageProvider: testImageProvider,
...@@ -313,10 +304,7 @@ void main() { ...@@ -313,10 +304,7 @@ void main() {
expect(imageCache.currentSize, 0); expect(imageCache.currentSize, 0);
}); });
testWidgets('ScrollAwareImageProvider resolves from ImageCache and does not set completer twice', testWidgets('ScrollAwareImageProvider resolves from ImageCache and does not set completer twice', (WidgetTester tester) async {
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
final GlobalKey<TestWidgetState> key = GlobalKey<TestWidgetState>(); final GlobalKey<TestWidgetState> key = GlobalKey<TestWidgetState>();
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
addTearDown(scrollController.dispose); addTearDown(scrollController.dispose);
...@@ -331,7 +319,7 @@ void main() { ...@@ -331,7 +319,7 @@ void main() {
final DisposableBuildContext context = DisposableBuildContext(key.currentState!); final DisposableBuildContext context = DisposableBuildContext(key.currentState!);
addTearDown(context.dispose); addTearDown(context.dispose);
final TestImageProvider testImageProvider = TestImageProvider(testImage.clone()); final TestImageProvider testImageProvider = TestImageProvider(cloneImage());
final ScrollAwareImageProvider<TestImageProvider> imageProvider = ScrollAwareImageProvider<TestImageProvider>( final ScrollAwareImageProvider<TestImageProvider> imageProvider = ScrollAwareImageProvider<TestImageProvider>(
context: context, context: context,
imageProvider: testImageProvider, imageProvider: testImageProvider,
...@@ -367,7 +355,6 @@ void main() { ...@@ -367,7 +355,6 @@ void main() {
}); });
testWidgets('ScrollAwareImageProvider does not block LRU updates to image cache', testWidgets('ScrollAwareImageProvider does not block LRU updates to image cache',
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(), experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async { (WidgetTester tester) async {
final int oldSize = imageCache.maximumSize; final int oldSize = imageCache.maximumSize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment