From 2ad227d49d3567b16cd4be4b349161e9cdb694c0 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Fri, 25 Oct 2024 13:05:05 -0700 Subject: [PATCH] When writing an updated package manifest in tests fails, try again Package resolving can open Package.swift in exclusive mode on Windows, which prevents us from writing the new package manifest. Keep retrying until we get a successful write. This matches what a user would do. --- Tests/SourceKitLSPTests/WorkspaceTests.swift | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Tests/SourceKitLSPTests/WorkspaceTests.swift b/Tests/SourceKitLSPTests/WorkspaceTests.swift index af6bce26c..53ddfceeb 100644 --- a/Tests/SourceKitLSPTests/WorkspaceTests.swift +++ b/Tests/SourceKitLSPTests/WorkspaceTests.swift @@ -585,12 +585,22 @@ final class WorkspaceTests: XCTestCase { let packageBManifestPath = project.scratchDirectory .appendingPathComponent("PackageB") .appendingPathComponent("Package.swift") - try newPackageManifest.write( - to: packageBManifestPath, - atomically: true, - encoding: .utf8 - ) + // Package resolving can open Package.swift in exclusive mode on Windows, which prevents us from writing the new + // package manifest. Keep retrying until we get a successful write. This matches what a user would do. + try await repeatUntilExpectedResult { + do { + try newPackageManifest.write( + to: packageBManifestPath, + atomically: true, + encoding: .utf8 + ) + return true + } catch { + logger.error("Writing new package manifest failed, will retry: \(error.forLogging)") + return false + } + } project.testClient.send( DidChangeWatchedFilesNotification(changes: [ FileEvent(uri: DocumentURI(packageBManifestPath), type: .changed)