Skip to content

Commit 2ad227d

Browse files
committed
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.
1 parent 9e9579d commit 2ad227d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Tests/SourceKitLSPTests/WorkspaceTests.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,22 @@ final class WorkspaceTests: XCTestCase {
585585
let packageBManifestPath = project.scratchDirectory
586586
.appendingPathComponent("PackageB")
587587
.appendingPathComponent("Package.swift")
588-
try newPackageManifest.write(
589-
to: packageBManifestPath,
590-
atomically: true,
591-
encoding: .utf8
592-
)
593588

589+
// Package resolving can open Package.swift in exclusive mode on Windows, which prevents us from writing the new
590+
// package manifest. Keep retrying until we get a successful write. This matches what a user would do.
591+
try await repeatUntilExpectedResult {
592+
do {
593+
try newPackageManifest.write(
594+
to: packageBManifestPath,
595+
atomically: true,
596+
encoding: .utf8
597+
)
598+
return true
599+
} catch {
600+
logger.error("Writing new package manifest failed, will retry: \(error.forLogging)")
601+
return false
602+
}
603+
}
594604
project.testClient.send(
595605
DidChangeWatchedFilesNotification(changes: [
596606
FileEvent(uri: DocumentURI(packageBManifestPath), type: .changed)

0 commit comments

Comments
 (0)