@@ -2633,14 +2633,18 @@ final class BackgroundIndexingTests: XCTestCase {
26332633 func testTargetsAreIndexedInDependencyOrder( ) async throws {
26342634 // We want to prepare low-level targets before high-level targets to make progress on indexing more quickly.
26352635 let preparationRequests = ThreadSafeBox < [ BuildTargetPrepareRequest ] > ( initialValue: [ ] )
2636+ let twoPreparationRequestsReceived = self . expectation ( description: " Received two preparation requests " )
26362637 let testHooks = Hooks (
26372638 buildServerHooks: BuildServerHooks ( preHandleRequest: { request in
26382639 if let request = request as? BuildTargetPrepareRequest {
26392640 preparationRequests. value. append ( request)
2641+ if preparationRequests. value. count >= 2 {
2642+ twoPreparationRequestsReceived. fulfill ( )
2643+ }
26402644 }
26412645 } )
26422646 )
2643- _ = try await SwiftPMTestProject (
2647+ let project = try await SwiftPMTestProject (
26442648 files: [
26452649 " LibA/LibA.swift " : " " ,
26462650 " LibB/LibB.swift " : " " ,
@@ -2656,15 +2660,20 @@ final class BackgroundIndexingTests: XCTestCase {
26562660 """ ,
26572661 hooks: testHooks,
26582662 enableBackgroundIndexing: true ,
2659- pollIndex: true
2663+ pollIndex: false
26602664 )
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)
26612669 XCTAssertEqual (
26622670 preparationRequests. value. flatMap ( \. targets) ,
26632671 [
26642672 try BuildTargetIdentifier ( target: " LibA " , destination: . target) ,
26652673 try BuildTargetIdentifier ( target: " LibB " , destination: . target) ,
26662674 ]
26672675 )
2676+ withExtendedLifetime ( project) { }
26682677 }
26692678
26702679 func testIndexingProgressDoesNotGetStuckIfThereAreNoSourceFilesInTarget( ) async throws {
0 commit comments