Repository navigation
Improve temp test dir cleanup code - #10025
Conversation
There was a problem hiding this comment.
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.
| 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/'); |
There was a problem hiding this comment.
[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.
| 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
- Prefix every comment with a severity: [MUST-FIX], [CONCERN], [NIT] to categorize issues clearly. (link)
….dart Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Fixes #4111
We change a few
tearDownAlltotearDown, usefinalTearDown, and introduce some try/finally blocks, to improve test temp code being deleted.