Skip to content

Commit

Permalink
Fix memory leaks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinVignal committed Jan 5, 2025
1 parent 201ac53 commit d078cec
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/rfw/test/argument_decoders_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void main() {
},
}))
..update(const LibraryName(<String>['test']), parseLibraryFile('import core; widget root = SizedBox();'));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -235,6 +236,7 @@ void main() {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['test']), parseLibraryFile('import core; widget root = SizedBox();'));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down
2 changes: 2 additions & 0 deletions packages/rfw/test/core_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {
testWidgets('Core widgets', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -248,6 +249,7 @@ void main() {
testWidgets('More core widgets', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down
4 changes: 3 additions & 1 deletion packages/rfw/test/material_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ void main() {
const LibraryName testName = LibraryName(<String>['test']);

Runtime setupRuntime() {
return Runtime()
final Runtime runtime = Runtime()
..update(coreName, createCoreWidgets())
..update(materialName, createMaterialWidgets());
addTearDown(runtime.dispose);
return runtime;
}

setUpAll(() {
Expand Down
1 change: 1 addition & 0 deletions packages/rfw/test/readme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ void main() {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['material']), createMaterialWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(parseDataFile(gameData));
for (final String region in rawRemoteWidgetSnippets.keys) {
final String body = rawRemoteWidgetSnippets[region]!;
Expand Down
2 changes: 2 additions & 0 deletions packages/rfw/test/remote_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ void main() {
import core;
widget root = Placeholder();
'''));
addTearDown(runtime1.dispose);
final Runtime runtime2 = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets())
..update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
widget root = Container();
'''));
addTearDown(runtime2.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down
37 changes: 37 additions & 0 deletions packages/rfw/test/runtime_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
testWidgets('list lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[ 0, 1, 2, 3, 4 ],
});
Expand Down Expand Up @@ -55,6 +56,7 @@ void main() {
return const SizedBox.shrink();
},
}));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[
<String, Object?>{ 'a': 0 },
Expand Down Expand Up @@ -131,6 +133,7 @@ void main() {
testWidgets('updateText, updateBinary, clearLibraries', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -167,6 +170,7 @@ void main() {
testWidgets('Runtime cached build', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -203,6 +207,7 @@ void main() {
..update(const LibraryName(<String>['b']), parseLibraryFile('''
import a;
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -219,6 +224,7 @@ void main() {
..update(const LibraryName(<String>['a']), parseLibraryFile('''
import a;
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -235,6 +241,7 @@ void main() {
..update(const LibraryName(<String>['a']), parseLibraryFile('''
import b;
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -249,6 +256,7 @@ void main() {

testWidgets('Missing libraries in specified widget', (WidgetTester tester) async {
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -267,6 +275,7 @@ void main() {
import b;
widget widget = test();
'''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -282,6 +291,7 @@ void main() {
testWidgets('Missing widget', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['a']), parseLibraryFile(''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -297,6 +307,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -327,6 +338,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -350,6 +362,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
expect(runtime.libraries.length, 1);
final LibraryName libraryName = runtime.libraries.entries.first.key;
expect('$libraryName', 'core');
Expand All @@ -362,6 +375,7 @@ void main() {
testWidgets('Runtime', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -389,6 +403,7 @@ void main() {
testWidgets('DynamicContent', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -435,6 +450,7 @@ void main() {
testWidgets('binding loop variables', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[
<String, Object?>{
Expand Down Expand Up @@ -600,6 +616,7 @@ void main() {
testWidgets('list lookup of esoteric values', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -720,6 +737,7 @@ void main() {
testWidgets('data lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'map': <String, Object?>{ 'list': <Object?>[ 0xAB ] },
});
Expand All @@ -744,6 +762,7 @@ void main() {
testWidgets('args lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -767,6 +786,7 @@ void main() {
testWidgets('state lookup', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -789,6 +809,7 @@ void main() {
testWidgets('switch', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -824,6 +845,7 @@ void main() {
testWidgets('events with arguments', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -872,6 +894,7 @@ void main() {
testWidgets('_CurriedWidget toStrings', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
runtime.update(const LibraryName(<String>['test']), parseLibraryFile('''
import core;
Expand Down Expand Up @@ -911,6 +934,7 @@ void main() {
testWidgets('state setting', (WidgetTester tester) async {
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['core']), createCoreWidgets());
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand Down Expand Up @@ -1029,6 +1053,7 @@ void main() {

testWidgets('DataSource', (WidgetTester tester) async {
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<String> eventLog = <String>[];
await tester.pumpWidget(
Expand Down Expand Up @@ -1094,6 +1119,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
runtime.update(coreLibraryName, createCoreWidgets());
runtime.update(localLibraryName, LocalWidgetLibrary(<String, LocalWidgetBuilder> {
Expand Down Expand Up @@ -1127,6 +1153,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
const String expectedErrorMessage = 'Not a builder at [builder] (got core:Text {} {text: Not a builder :/}) for local:Builder.';

Expand Down Expand Up @@ -1163,6 +1190,7 @@ void main() {
};
final Runtime runtime = Runtime()
..update(const LibraryName(<String>['a']), parseLibraryFile(''));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
await tester.pumpWidget(
RemoteWidget(
Expand All @@ -1182,6 +1210,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1214,6 +1243,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1247,6 +1277,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1283,6 +1314,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object>{'value': 0});
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1322,6 +1354,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final List<RfwEvent> dispatchedEvents = <RfwEvent>[];
final Finder textFinder = find.byType(Text);
Expand Down Expand Up @@ -1363,6 +1396,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);
runtime.update(coreLibraryName, createCoreWidgets());
Expand Down Expand Up @@ -1408,6 +1442,7 @@ void main() {
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Map<String, VoidCallback> handlers = <String, VoidCallback>{};
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'a1': 'apricot',
'b1': 'blueberry',
Expand Down Expand Up @@ -1474,6 +1509,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);

Expand Down Expand Up @@ -1522,6 +1558,7 @@ void main() {
const LibraryName localLibraryName = LibraryName(<String>['local']);
const LibraryName remoteLibraryName = LibraryName(<String>['remote']);
final Runtime runtime = Runtime();
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent();
final Finder textFinder = find.byType(Text);
runtime.update(coreLibraryName, createCoreWidgets());
Expand Down
1 change: 1 addition & 0 deletions packages/rfw/test/source_locations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ widget verify { state: true } = switch args.value.c.0 {
// We use the actual source text as the sourceIdentifier to make it trivial to find the source contents.
// In normal operation, the sourceIdentifier would be the file name or some similar object.
..update(const LibraryName(<String>['test']), parseLibraryFile(sourceFile, sourceIdentifier: sourceFile));
addTearDown(runtime.dispose);
final DynamicContent data = DynamicContent(<String, Object?>{
'list': <Object?>[
<String, Object?>{
Expand Down

0 comments on commit d078cec

Please sign in to comment.