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
This commit is contained in:
Alex Hoppen
2024-04-18 16:18:01 -07:00
parent b9af0cf2ef
commit fc8a7301b2
3 changed files with 6 additions and 2 deletions

View File

@@ -12,6 +12,7 @@
import Dispatch
import IndexStoreDB
import LSPLogging
import SKCore
import SKSupport
@@ -62,6 +63,7 @@ public actor SourceKitIndexDelegate: IndexDelegate {
}
private func indexChanged() {
logger.debug("IndexStoreDB changed")
for callback in mainFilesChangedCallbacks {
queue.async {
await callback()

View File

@@ -584,7 +584,7 @@ final class RenameTests: XCTestCase {
name: "MyLibrary",
targets: [
.target(
name: "MyLibrary",
name: "MyLibrary",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-objc-attr-requires-foundation-module"])]
)
]
@@ -635,7 +635,7 @@ final class RenameTests: XCTestCase {
name: "MyLibrary",
targets: [
.target(
name: "MyLibrary",
name: "MyLibrary",
swiftSettings: [.unsafeFlags(["-Xfrontend", "-disable-objc-attr-requires-foundation-module"])]
)
]
@@ -1158,6 +1158,7 @@ final class RenameTests: XCTestCase {
)
try await SwiftPMTestProject.build(at: project.scratchDirectory)
_ = try await project.testClient.send(PollIndexRequest())
let resultAfterFileMove = try await project.testClient.send(
RenameRequest(textDocument: TextDocumentIdentifier(callerUri), position: callerPositions["3"], newName: "bar")

View File

@@ -247,6 +247,7 @@ final class TestDiscoveryTests: XCTestCase {
)
try await SwiftPMTestProject.build(at: project.scratchDirectory)
_ = try await project.testClient.send(PollIndexRequest())
// After indexing, we know that `LooksLikeTestCaseButIsNot` does not inherit from `XCTestCase` and we don't report any tests.
let indexBasedTests = try await project.testClient.send(