1414import Foundation
1515import LanguageServerProtocol
1616import SKTestSupport
17+ import SemanticIndex
1718@_spi ( Testing) import SourceKitLSP
1819import SwiftExtensions
1920import ToolchainRegistry
@@ -113,6 +114,9 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
113114 func testSyntacticOrIndexBasedXCTestsBasedOnWhetherFileIsIndexed( ) async throws {
114115 try SkipUnless . longTestsEnabled ( )
115116
117+ let initialIndexingFinished = AtomicBool ( initialValue: false )
118+ let syntacticWorkspaceRequestSent = WrappedSemaphore ( name: " Syntactic workspace request sent " )
119+
116120 let project = try await SwiftPMTestProject (
117121 files: [
118122 " Tests/MyLibraryTests/MyTests.swift " : """
@@ -126,9 +130,18 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
126130 """
127131 ] ,
128132 manifest: packageManifestWithTestTarget,
133+ hooks: Hooks (
134+ indexHooks: IndexHooks ( updateIndexStoreTaskDidStart: { _ in
135+ if initialIndexingFinished. value {
136+ syntacticWorkspaceRequestSent. waitOrXCTFail ( )
137+ }
138+ } )
139+ ) ,
129140 enableBackgroundIndexing: true
130141 )
131142
143+ initialIndexingFinished. value = true
144+
132145 let myTestsUri = try project. uri ( for: " MyTests.swift " )
133146
134147 // First get the tests from the original file contents, which are computed by the semantic index.
@@ -200,6 +213,8 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
200213 ]
201214 )
202215
216+ syntacticWorkspaceRequestSent. signal ( )
217+
203218 // After building again, we should have updated the updated the semantic index and realize that `NotQuiteTests` does
204219 // not inherit from XCTest and thus doesn't have any test methods.
205220
0 commit comments