Skip to content

Commit d566e2b

Browse files
committed
Retry updating Header.h in testBackgroundIndexingReindexesHeader
This fixes a nondeterministic test failure on Windows.
1 parent 17e2db0 commit d566e2b

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
@@ -507,11 +508,17 @@ final class BackgroundIndexingTests: XCTestCase {
507508
"""
508509
)
509510

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

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

0 commit comments

Comments
 (0)