@@ -2633,14 +2633,18 @@ final class BackgroundIndexingTests: XCTestCase {
2633
2633
func testTargetsAreIndexedInDependencyOrder( ) async throws {
2634
2634
// We want to prepare low-level targets before high-level targets to make progress on indexing more quickly.
2635
2635
let preparationRequests = ThreadSafeBox < [ BuildTargetPrepareRequest ] > ( initialValue: [ ] )
2636
+ let twoPreparationRequestsReceived = self . expectation ( description: " Received two preparation requests " )
2636
2637
let testHooks = Hooks (
2637
2638
buildServerHooks: BuildServerHooks ( preHandleRequest: { request in
2638
2639
if let request = request as? BuildTargetPrepareRequest {
2639
2640
preparationRequests. value. append ( request)
2641
+ if preparationRequests. value. count >= 2 {
2642
+ twoPreparationRequestsReceived. fulfill ( )
2643
+ }
2640
2644
}
2641
2645
} )
2642
2646
)
2643
- _ = try await SwiftPMTestProject (
2647
+ let project = try await SwiftPMTestProject (
2644
2648
files: [
2645
2649
" LibA/LibA.swift " : " " ,
2646
2650
" LibB/LibB.swift " : " " ,
@@ -2656,15 +2660,20 @@ final class BackgroundIndexingTests: XCTestCase {
2656
2660
""" ,
2657
2661
hooks: testHooks,
2658
2662
enableBackgroundIndexing: true ,
2659
- pollIndex: true
2663
+ pollIndex: false
2660
2664
)
2665
+ // We can't poll the index using `workspace/synchronize` because that elevates the priority of the indexing requests
2666
+ // in a non-deterministic order (due to the way ). If LibB's priority gets elevated before LibA's, then LibB will
2667
+ // get prepared first, which is contrary to the background behavior we want to check here.
2668
+ try await fulfillmentOfOrThrow ( twoPreparationRequestsReceived)
2661
2669
XCTAssertEqual (
2662
2670
preparationRequests. value. flatMap ( \. targets) ,
2663
2671
[
2664
2672
try BuildTargetIdentifier ( target: " LibA " , destination: . target) ,
2665
2673
try BuildTargetIdentifier ( target: " LibB " , destination: . target) ,
2666
2674
]
2667
2675
)
2676
+ withExtendedLifetime ( project) { }
2668
2677
}
2669
2678
2670
2679
func testIndexingProgressDoesNotGetStuckIfThereAreNoSourceFilesInTarget( ) async throws {
0 commit comments