@@ -2585,6 +2585,48 @@ final class BackgroundIndexingTests: XCTestCase {
2585
2585
let symbols = try await project. testClient. send ( WorkspaceSymbolsRequest ( query: " myTestFu " ) )
2586
2586
XCTAssertEqual ( symbols? . compactMap ( \. symbolInformation? . name) , [ " myTestFunc() " ] )
2587
2587
}
2588
+
2589
+ func testEnsureSymbolsLoadedIntoIndexstoreDbWhenIndexingHasFinished( ) async throws {
2590
+ let testSetupComplete = AtomicBool ( initialValue: false )
2591
+ let updateIndexStoreStarted = self . expectation ( description: " Update index store started " )
2592
+ let project = try await SwiftPMTestProject (
2593
+ files: [
2594
+ " Test.swift " : " "
2595
+ ] ,
2596
+ options: . testDefault( experimentalFeatures: [ . isIndexingRequest] ) ,
2597
+ hooks: Hooks (
2598
+ indexHooks: IndexHooks ( updateIndexStoreTaskDidStart: { _ in
2599
+ guard testSetupComplete. value else {
2600
+ return
2601
+ }
2602
+ updateIndexStoreStarted. fulfill ( )
2603
+ } )
2604
+ ) ,
2605
+ enableBackgroundIndexing: true ,
2606
+ pollIndex: false
2607
+ )
2608
+
2609
+ try await project. changeFileOnDisk ( " Test.swift " , newMarkedContents: " " )
2610
+ try await project. testClient. send ( SynchronizeRequest ( index: true ) )
2611
+ let symbolsBeforeUpdate = try await project. testClient. send ( WorkspaceSymbolsRequest ( query: " myTestFu " ) )
2612
+ XCTAssertEqual ( symbolsBeforeUpdate, [ ] )
2613
+
2614
+ testSetupComplete. value = true
2615
+ try await project. changeFileOnDisk (
2616
+ " Test.swift " ,
2617
+ newMarkedContents: """
2618
+ func myTestFunc() {}
2619
+ """
2620
+ )
2621
+ try await fulfillmentOfOrThrow ( [ updateIndexStoreStarted] )
2622
+ try await repeatUntilExpectedResult ( sleepInterval: . milliseconds( 2 ) ) {
2623
+ try await !project. testClient. send ( IsIndexingRequest ( ) ) . indexing
2624
+ }
2625
+ // Check that the newly added function has been registered in indexstore-db once indexing is done and that there is
2626
+ // no time gap in which indexing has finished but the new unit has not been loaded into indexstore-db yet.
2627
+ let symbols = try await project. testClient. send ( WorkspaceSymbolsRequest ( query: " myTestFu " ) )
2628
+ XCTAssertEqual ( symbols? . count, 1 )
2629
+ }
2588
2630
}
2589
2631
2590
2632
extension HoverResponseContents {
0 commit comments