Skip to content

Commit

Permalink
Add RestorationManager disposals in test/services/restoration_test.da…
Browse files Browse the repository at this point in the history
…rt. (#135218)
  • Loading branch information
ksokolovskyi authored Sep 21, 2023
1 parent 7771884 commit 4204f07
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/flutter/test/services/restoration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void main() {
});

final RestorationManager manager = RestorationManager();
addTearDown(manager.dispose);
final Future<RestorationBucket?> rootBucketFuture = manager.rootBucket;
RestorationBucket? rootBucket;
rootBucketFuture.then((RestorationBucket? bucket) {
Expand Down Expand Up @@ -65,20 +66,17 @@ void main() {
});
expect(synchronousBucket, isNotNull);
expect(synchronousBucket, same(rootBucket));
},
// TODO(NobodyForNothing): Remove after fixing and cover remaining file
// with leak tests https://github.com/flutter/flutter/issues/134831
leakTrackingTestConfig: const LeakTrackingTestConfig(notDisposedAllowList:
<String, int?>{'RestorationManager': 1}));
});

testWidgets('root bucket received from engine before retrieval', (WidgetTester tester) async {
testWidgetsWithLeakTracking('root bucket received from engine before retrieval', (WidgetTester tester) async {
SystemChannels.restoration.setMethodCallHandler(null);
final List<MethodCall> callsToEngine = <MethodCall>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.restoration, (MethodCall call) async {
callsToEngine.add(call);
return null;
});
final RestorationManager manager = RestorationManager();
addTearDown(manager.dispose);

await _pushDataFromEngine(_createEncodedRestorationData1());

Expand All @@ -90,7 +88,7 @@ void main() {
expect(callsToEngine, isEmpty);
});

testWidgets('root bucket received while engine retrieval is pending', (WidgetTester tester) async {
testWidgetsWithLeakTracking('root bucket received while engine retrieval is pending', (WidgetTester tester) async {
SystemChannels.restoration.setMethodCallHandler(null);
final List<MethodCall> callsToEngine = <MethodCall>[];
final Completer<Map<dynamic, dynamic>> result = Completer<Map<dynamic, dynamic>>();
Expand All @@ -99,6 +97,7 @@ void main() {
return result.future;
});
final RestorationManager manager = RestorationManager();
addTearDown(manager.dispose);

RestorationBucket? rootBucket;
manager.rootBucket.then((RestorationBucket? bucket) => rootBucket = bucket);
Expand All @@ -120,11 +119,12 @@ void main() {
expect(rootBucket2!.contains('foo'), isFalse);
});

testWidgets('root bucket is properly replaced when new data is available', (WidgetTester tester) async {
testWidgetsWithLeakTracking('root bucket is properly replaced when new data is available', (WidgetTester tester) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.restoration, (MethodCall call) async {
return _createEncodedRestorationData1();
});
final RestorationManager manager = RestorationManager();
addTearDown(manager.dispose);
RestorationBucket? rootBucket;
manager.rootBucket.then((RestorationBucket? bucket) {
rootBucket = bucket;
Expand Down Expand Up @@ -160,7 +160,7 @@ void main() {
expect(newChild.read<String>('bar'), 'Hello');
});

testWidgets('returns null as root bucket when restoration is disabled', (WidgetTester tester) async {
testWidgetsWithLeakTracking('returns null as root bucket when restoration is disabled', (WidgetTester tester) async {
final List<MethodCall> callsToEngine = <MethodCall>[];
final Completer<Map<dynamic, dynamic>> result = Completer<Map<dynamic, dynamic>>();
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.restoration, (MethodCall call) {
Expand All @@ -171,6 +171,7 @@ void main() {
final RestorationManager manager = RestorationManager()..addListener(() {
listenerCount++;
});
addTearDown(manager.dispose);
RestorationBucket? rootBucket;
bool rootBucketResolved = false;
manager.rootBucket.then((RestorationBucket? bucket) {
Expand Down Expand Up @@ -203,7 +204,7 @@ void main() {
expect(rootBucket, isNull);
});

testWidgets('flushData', (WidgetTester tester) async {
testWidgetsWithLeakTracking('flushData', (WidgetTester tester) async {
final List<MethodCall> callsToEngine = <MethodCall>[];
final Completer<Map<dynamic, dynamic>> result = Completer<Map<dynamic, dynamic>>();
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.restoration, (MethodCall call) {
Expand All @@ -212,6 +213,7 @@ void main() {
});

final RestorationManager manager = RestorationManager();
addTearDown(manager.dispose);
final Future<RestorationBucket?> rootBucketFuture = manager.rootBucket;
RestorationBucket? rootBucket;
rootBucketFuture.then((RestorationBucket? bucket) {
Expand Down Expand Up @@ -239,13 +241,14 @@ void main() {
expect(callsToEngine, hasLength(1));
});

testWidgets('isReplacing', (WidgetTester tester) async {
testWidgetsWithLeakTracking('isReplacing', (WidgetTester tester) async {
final Completer<Map<dynamic, dynamic>> result = Completer<Map<dynamic, dynamic>>();
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.restoration, (MethodCall call) {
return result.future;
});

final TestRestorationManager manager = TestRestorationManager();
addTearDown(manager.dispose);
expect(manager.isReplacing, isFalse);

RestorationBucket? rootBucket;
Expand Down

0 comments on commit 4204f07

Please sign in to comment.