@@ -695,7 +695,16 @@ final class BackgroundIndexingTests: XCTestCase {
695
695
DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: try project. uri ( for: " LibA.swift " ) , type: . changed) ] )
696
696
)
697
697
698
- // Quickly flip through all files
698
+ // Quickly flip through all files. The way the test is designed to work is as follows:
699
+ // - LibB.swift gets opened and prepared. Preparation is simulated to take a long time until both LibC.swift and
700
+ // LibD.swift have been opened.
701
+ // - LibC.swift gets opened. This queues preparation of LibC but doesn't cancel preparation of LibB because we
702
+ // don't cancel in-progress preparation tasks to guarantee forward progress (see comment at the end of
703
+ // `SemanticIndexManager.prepare`).
704
+ // - Now LibD.swift gets opened. This cancels preparation of LibC which actually cancels LibC's preparation for
705
+ // real because LibC's preparation hasn't started yet (it's only queued).
706
+ // Thus, the only targets that are being prepared are LibB and LibD, which is checked by the
707
+ // `ExpectedIndexTaskTracker`.
699
708
_ = try project. openDocument ( " LibB.swift " )
700
709
try libBStartedPreparation. waitOrThrow ( )
701
710
@@ -707,6 +716,9 @@ final class BackgroundIndexingTests: XCTestCase {
707
716
_ = try await project. testClient. send ( BarrierRequest ( ) )
708
717
_ = try project. openDocument ( " LibD.swift " )
709
718
719
+ // Send a barrier request to ensure we have finished opening LibD before allowing the preparation of LibB to finish.
720
+ _ = try await project. testClient. send ( BarrierRequest ( ) )
721
+
710
722
allDocumentsOpened. signal ( )
711
723
try libDPreparedForEditing. waitOrThrow ( )
712
724
}
0 commit comments