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