Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When writing an updated package manifest in tests fails, try again #1785

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Tests/SourceKitLSPTests/WorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down