Skip to content

Improve temp test dir cleanup code - #10025

Merged
srawlins merged 6 commits into
flutter:masterfrom
srawlins:clean-tmp
Oct 1, 2026
Merged

srawlins merged 6 commits into
flutter:masterfrom
srawlins:clean-tmp

Conversation

@srawlins

Copy link
Copy Markdown
Contributor

Fixes #4111

We change a few tearDownAll to tearDown, use finalTearDown, and introduce some try/finally blocks, to improve test temp code being deleted.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves test environment cleanup and robustness across several DevTools packages by utilizing pattern matching for null checks, migrating from tearDownAll to tearDown where appropriate, and wrapping teardown logic in try/finally blocks to guarantee resource cleanup. The review feedback highlights several areas for further improvement: wrapping asynchronous teardown and process cleanup steps in try/finally blocks to prevent leaked directories on failure, removing a redundant Directory instantiation in flutter_test_environment.dart, and checking for the existence of the build/ directory before deletion in the rollback command to avoid crashes on clean clones.

Comment thread packages/devtools_app/test/test_infra/flutter_test_environment.dart
Comment thread packages/devtools_shared/test/utils/file_utils_test.dart
Comment on lines +62 to +68
final buildDir = io.Directory(
'${repo.repoPath}/packages/devtools/build/',
);
await buildDir.delete(recursive: true);
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[CONCERN] If the build/ directory does not exist (for example, in a clean repository clone), buildDir.delete(recursive: true) will throw a FileSystemException and halt the rollback command.

Consider checking if the directory exists before attempting to delete it.

Suggested change
final buildDir = io.Directory(
'${repo.repoPath}/packages/devtools/build/',
);
await buildDir.delete(recursive: true);
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');
final buildDir = io.Directory(
'${repo.repoPath}/packages/devtools/build/',
);
if (await buildDir.exists()) {
await buildDir.delete(recursive: true);
}
await io.Directory(
'${extractDir.path}build/',
).rename('${repo.repoPath}/packages/devtools/build/');
References
  1. Prefix every comment with a severity: [MUST-FIX], [CONCERN], [NIT] to categorize issues clearly. (link)

@srawlins
srawlins requested a review from johnpryan September 30, 2026 14:25

@johnpryan johnpryan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@srawlins
srawlins merged commit cb22250 into flutter:master Oct 1, 2026
51 checks passed
@srawlins
srawlins deleted the clean-tmp branch October 1, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Look into memory bloat after running flutter test

2 participants