Skip to content

Commit fc8a730

Browse files
committed
Wait for indexstore-db to update after building a SwiftPM project in tests
Otherwise we can get into race conditions where we run a request before the index has actually been updated. While at it, also add logging when IndexStoreDB has been updated. rdar://126635046
1 parent b9af0cf commit fc8a730

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Sources/SourceKitLSP/SourceKitIndexDelegate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import Dispatch
1414
import IndexStoreDB
15+
import LSPLogging
1516
import SKCore
1617
import SKSupport
1718

@@ -62,6 +63,7 @@ public actor SourceKitIndexDelegate: IndexDelegate {
6263
}
6364

6465
private func indexChanged() {
66+
logger.debug("IndexStoreDB changed")
6567
for callback in mainFilesChangedCallbacks {
6668
queue.async {
6769
await callback()

Tests/SourceKitLSPTests/RenameTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ final class RenameTests: XCTestCase {
584584
name: "MyLibrary",
585585
targets: [
586586
.target(
587-
name: "MyLibrary",
587+
name: "MyLibrary",
588588
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-objc-attr-requires-foundation-module"])]
589589
)
590590
]
@@ -635,7 +635,7 @@ final class RenameTests: XCTestCase {
635635
name: "MyLibrary",
636636
targets: [
637637
.target(
638-
name: "MyLibrary",
638+
name: "MyLibrary",
639639
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-objc-attr-requires-foundation-module"])]
640640
)
641641
]
@@ -1158,6 +1158,7 @@ final class RenameTests: XCTestCase {
11581158
)
11591159

11601160
try await SwiftPMTestProject.build(at: project.scratchDirectory)
1161+
_ = try await project.testClient.send(PollIndexRequest())
11611162

11621163
let resultAfterFileMove = try await project.testClient.send(
11631164
RenameRequest(textDocument: TextDocumentIdentifier(callerUri), position: callerPositions["3️⃣"], newName: "bar")

Tests/SourceKitLSPTests/TestDiscoveryTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ final class TestDiscoveryTests: XCTestCase {
247247
)
248248

249249
try await SwiftPMTestProject.build(at: project.scratchDirectory)
250+
_ = try await project.testClient.send(PollIndexRequest())
250251

251252
// After indexing, we know that `LooksLikeTestCaseButIsNot` does not inherit from `XCTestCase` and we don't report any tests.
252253
let indexBasedTests = try await project.testClient.send(

0 commit comments

Comments
 (0)