@@ -693,7 +693,16 @@ final class BackgroundIndexingTests: XCTestCase {
693693 DidChangeWatchedFilesNotification ( changes: [ FileEvent ( uri: try project. uri ( for: " LibA.swift " ) , type: . changed) ] )
694694 )
695695
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`.
697706 _ = try project. openDocument ( " LibB.swift " )
698707 try libBStartedPreparation. waitOrThrow ( )
699708
@@ -705,6 +714,9 @@ final class BackgroundIndexingTests: XCTestCase {
705714 _ = try await project. testClient. send ( BarrierRequest ( ) )
706715 _ = try project. openDocument ( " LibD.swift " )
707716
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+
708720 allDocumentsOpened. signal ( )
709721 try libDPreparedForEditing. waitOrThrow ( )
710722 }
0 commit comments