Skip to content

Commit 194d340

Browse files
authored
Merge pull request #1914 from ahoppen/retry-updating-headerh
Retry updating `Header.h` in `testBackgroundIndexingReindexesHeader`
2 parents 48389c7 + d566e2b commit 194d340

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import BuildSystemIntegration
1414
import LanguageServerProtocol
1515
import LanguageServerProtocolExtensions
16+
import SKLogging
1617
import SKOptions
1718
import SKTestSupport
1819
import SemanticIndex
@@ -506,11 +507,17 @@ final class BackgroundIndexingTests: XCTestCase {
506507
"""
507508
)
508509

509-
try headerNewMarkedContents.write(
510-
to: try XCTUnwrap(uri.fileURL),
511-
atomically: true,
512-
encoding: .utf8
513-
)
510+
// clangd might have Header.h open, which prevents us from updating it. Keep retrying until we get a successful
511+
// write. This matches what a user would do.
512+
try await repeatUntilExpectedResult {
513+
do {
514+
try headerNewMarkedContents.write(to: try XCTUnwrap(uri.fileURL), atomically: true, encoding: .utf8)
515+
return true
516+
} catch {
517+
logger.error("Writing new Header.h failed, will retry: \(error.forLogging)")
518+
return false
519+
}
520+
}
514521

515522
project.testClient.send(DidChangeWatchedFilesNotification(changes: [FileEvent(uri: uri, type: .changed)]))
516523
try await project.testClient.send(PollIndexRequest())

0 commit comments

Comments
 (0)