From f4e7c3ca7b255fb1d93a6b60cabb0de9c5d9fe1e Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Thu, 3 Jul 2025 09:01:37 -0700 Subject: [PATCH] [analysis_server] Clean up some temp files after test runs + tweak the names of all temp folders created by tests to be more consistent, and more specific so it's easier to tell which are not being cleaned up. Change-Id: Iabc58576ed7070ebca00a22c7ebb5909b98aa500 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433821 Reviewed-by: Samuel Rawlins Commit-Queue: Samuel Rawlins Reviewed-by: Brian Wilkerson Commit-Queue: Brian Wilkerson --- .../lsp_server/integration_tests.dart | 10 +++++++++- .../server/blaze_changes_test.dart | 11 ++++++++-- .../support/integration_tests.dart | 20 +++++++++++++------ .../src/server/sdk_configuration_test.dart | 4 +++- .../test/support/sdk_paths.dart | 4 ++-- .../test/timing/timing_framework.dart | 4 +++- .../tool/benchmark_tools/run_utils.dart | 4 +++- 7 files changed, 43 insertions(+), 14 deletions(-) diff --git a/pkg/analysis_server/integration_test/lsp_server/integration_tests.dart b/pkg/analysis_server/integration_test/lsp_server/integration_tests.dart index 9f57f77354c..d6c29df7223 100644 --- a/pkg/analysis_server/integration_test/lsp_server/integration_tests.dart +++ b/pkg/analysis_server/integration_test/lsp_server/integration_tests.dart @@ -44,6 +44,10 @@ abstract class AbstractLspAnalysisServerIntegrationTest /// be applied in the same way a real client would apply them. final _overlayContent = {}; + /// Temporary folders created by the test that should be deleted (recursively) + /// during [tearDown]. + final List _temporaryFolders = []; + LspByteStreamServerChannel get channel => client!.channel!; @override @@ -137,8 +141,9 @@ abstract class AbstractLspAnalysisServerIntegrationTest // Set up temporary folder for the test. projectFolderPath = Directory.systemTemp - .createTempSync('analysisServer') + .createTempSync('analysisServer_test_integration_lspProject') .resolveSymbolicLinksSync(); + _temporaryFolders.add(projectFolderPath); newFolder(projectFolderPath); newFolder(path.join(projectFolderPath, 'lib')); mainFilePath = path.join(projectFolderPath, 'lib', 'main.dart'); @@ -168,6 +173,9 @@ abstract class AbstractLspAnalysisServerIntegrationTest void tearDown() { // TODO(dantup): Graceful shutdown? client?.close(); + for (var temporaryFolder in _temporaryFolders) { + Directory(temporaryFolder).deleteSync(recursive: true); + } } } diff --git a/pkg/analysis_server/integration_test/server/blaze_changes_test.dart b/pkg/analysis_server/integration_test/server/blaze_changes_test.dart index 86cca47efe5..ccbba182c6c 100644 --- a/pkg/analysis_server/integration_test/server/blaze_changes_test.dart +++ b/pkg/analysis_server/integration_test/server/blaze_changes_test.dart @@ -41,6 +41,10 @@ class BlazeChangesTest extends AbstractAnalysisServerIntegrationTest { late String blazeGenfilesPath; late Directory oldSourceDirectory; + /// Temporary folders created by the test that should be deleted (recursively) + /// during [tearDown]. + final List _temporaryFolders = []; + String inTmpDir(String relative) => path.join(tmpPath, relative.replaceAll('/', path.separator)); @@ -55,9 +59,10 @@ class BlazeChangesTest extends AbstractAnalysisServerIntegrationTest { tmpPath = Directory( Directory.systemTemp - .createTempSync('analysisServer') + .createTempSync('analysisServer_test_integration_blazeProject') .resolveSymbolicLinksSync(), ).path; + _temporaryFolders.add(tmpPath); workspacePath = inTmpDir('workspace_root'); writeFile(inWorkspace(file_paths.blazeWorkspaceMarker), ''); @@ -81,7 +86,9 @@ class BlazeChangesTest extends AbstractAnalysisServerIntegrationTest { @override Future tearDown() async { - Directory(tmpPath).deleteSync(recursive: true); + for (var temporaryFolder in _temporaryFolders) { + Directory(temporaryFolder).deleteSync(recursive: true); + } sourceDirectory = oldSourceDirectory; await super.tearDown(); } diff --git a/pkg/analysis_server/integration_test/support/integration_tests.dart b/pkg/analysis_server/integration_test/support/integration_tests.dart index 1737dfba6eb..6592262d48c 100644 --- a/pkg/analysis_server/integration_test/support/integration_tests.dart +++ b/pkg/analysis_server/integration_test/support/integration_tests.dart @@ -116,6 +116,10 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest @override final Server server = Server(); + /// Temporary folders created by the test that should be deleted (recursively) + /// during [tearDown]. + final List _temporaryFolders = []; + /// Temporary directory in which source files can be stored. late Directory sourceDirectory; @@ -223,10 +227,13 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest /// [sourceDirectory] is created. Future setUp() async { var pathContext = resourceProvider.pathContext; - var tempDirectoryPath = - Directory.systemTemp - .createTempSync('analysisServer') - .resolveSymbolicLinksSync(); + var testTemporaryDirectory = Directory( + Directory.systemTemp + .createTempSync('analysisServer_test_integration_project') + .resolveSymbolicLinksSync(), + ); + var tempDirectoryPath = testTemporaryDirectory.path; + _temporaryFolders.add(tempDirectoryPath); sourceDirectory = Directory(pathContext.join(tempDirectoryPath, 'app')) ..createSync(); packagesDirectory = Directory( @@ -323,8 +330,9 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest @mustCallSuper Future tearDown() { return shutdownIfNeeded().then((_) { - sourceDirectory.deleteSync(recursive: true); - packagesDirectory.deleteSync(recursive: true); + for (var temporaryFolder in _temporaryFolders) { + deleteFolder(temporaryFolder); + } }); } diff --git a/pkg/analysis_server/test/src/server/sdk_configuration_test.dart b/pkg/analysis_server/test/src/server/sdk_configuration_test.dart index 6a7427b8c82..c578fdf46f4 100644 --- a/pkg/analysis_server/test/src/server/sdk_configuration_test.dart +++ b/pkg/analysis_server/test/src/server/sdk_configuration_test.dart @@ -13,7 +13,9 @@ void main() { Directory? tempDir; Directory createTempDir() { - return tempDir = Directory.systemTemp.createTempSync('SdkConfiguration'); + return tempDir = Directory.systemTemp.createTempSync( + 'analysisServer_test_sdkConfiguration', + ); } tearDown(() { diff --git a/pkg/analysis_server/test/support/sdk_paths.dart b/pkg/analysis_server/test/support/sdk_paths.dart index 31f2fc6bea8..983f081e327 100644 --- a/pkg/analysis_server/test/support/sdk_paths.dart +++ b/pkg/analysis_server/test/support/sdk_paths.dart @@ -53,7 +53,7 @@ Future getAnalysisServerPath(String dartSdkPath) async { // This is a simple way to run from source using the test_all file that // runs all tests in a single isolate and will trigger a single // compilation for all integration tests. - // - An path to a pre-compiled snapshot. + // - A path to a pre-compiled snapshot. // This allows configuring VS Code to pre-compile the snapshot once and // then use 'dart test' which will run each sweet in a separate isolate // without each test/isolate having to compile. @@ -85,7 +85,7 @@ Future _compileTemporaryServerSnapshot() async { var dartBinary = Platform.resolvedExecutable; var tempSnapshotDirectory = Directory.systemTemp.createTempSync( - 'dart_analysis_server_tests', + 'analysisServer_test_integration_compiledServer', ); var tempSnapshotFilePath = path.join( tempSnapshotDirectory.path, diff --git a/pkg/analysis_server/test/timing/timing_framework.dart b/pkg/analysis_server/test/timing/timing_framework.dart index 652749de8ac..ec0e229bc97 100644 --- a/pkg/analysis_server/test/timing/timing_framework.dart +++ b/pkg/analysis_server/test/timing/timing_framework.dart @@ -137,7 +137,9 @@ abstract class TimingTest extends IntegrationTest { /// iterations. Future oneTimeSetUp() { server = Server(); - sourceDirectory = Directory.systemTemp.createTempSync('analysisServer'); + sourceDirectory = Directory.systemTemp.createTempSync( + 'analysisServer_test_timing', + ); var serverConnected = Completer(); onServerConnected.listen((_) { serverConnected.complete(); diff --git a/pkg/analysis_server/tool/benchmark_tools/run_utils.dart b/pkg/analysis_server/tool/benchmark_tools/run_utils.dart index 6e85958009d..26b305512bf 100644 --- a/pkg/analysis_server/tool/benchmark_tools/run_utils.dart +++ b/pkg/analysis_server/tool/benchmark_tools/run_utils.dart @@ -68,7 +68,9 @@ Future runHelper( caption = 'size $size'; } try { - Directory tmpDir = Directory.systemTemp.createTempSync('lsp_benchmark'); + Directory tmpDir = Directory.systemTemp.createTempSync( + 'analysisServer_benchmark', + ); try { Directory cacheDir = Directory.fromUri(tmpDir.uri.resolve('cache/')) ..createSync(recursive: true);