[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 <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny
2025-07-03 09:01:37 -07:00
committed by Commit Queue
parent 476f915edb
commit f4e7c3ca7b
7 changed files with 43 additions and 14 deletions
@@ -44,6 +44,10 @@ abstract class AbstractLspAnalysisServerIntegrationTest
/// be applied in the same way a real client would apply them.
final _overlayContent = <Uri, String>{};
/// Temporary folders created by the test that should be deleted (recursively)
/// during [tearDown].
final List<String> _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);
}
}
}
@@ -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<String> _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<void> tearDown() async {
Directory(tmpPath).deleteSync(recursive: true);
for (var temporaryFolder in _temporaryFolders) {
Directory(temporaryFolder).deleteSync(recursive: true);
}
sourceDirectory = oldSourceDirectory;
await super.tearDown();
}
@@ -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<String> _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<void> 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<void> tearDown() {
return shutdownIfNeeded().then((_) {
sourceDirectory.deleteSync(recursive: true);
packagesDirectory.deleteSync(recursive: true);
for (var temporaryFolder in _temporaryFolders) {
deleteFolder(temporaryFolder);
}
});
}
@@ -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(() {
@@ -53,7 +53,7 @@ Future<String> 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<String> _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,
@@ -137,7 +137,9 @@ abstract class TimingTest extends IntegrationTest {
/// iterations.
Future<void> oneTimeSetUp() {
server = Server();
sourceDirectory = Directory.systemTemp.createTempSync('analysisServer');
sourceDirectory = Directory.systemTemp.createTempSync(
'analysisServer_test_timing',
);
var serverConnected = Completer<void>();
onServerConnected.listen((_) {
serverConnected.complete();
@@ -68,7 +68,9 @@ Future<void> runHelper<E, F, G>(
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);