Skip to content

Commit e0f3a55

Browse files
authored
Merge pull request #1504 from ahoppen/6.0/fix-dont-stack-preparation-test
[6.0] Fix a nondeterministic test failure of `testDontStackTargetPreparationForEditorFunctionality`
2 parents b34ed66 + 59f6264 commit e0f3a55

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,16 @@ final class BackgroundIndexingTests: XCTestCase {
695695
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: try project.uri(for: "LibA.swift"), type: .changed)])
696696
)
697697

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`.
699708
_ = try project.openDocument("LibB.swift")
700709
try libBStartedPreparation.waitOrThrow()
701710

@@ -707,6 +716,9 @@ final class BackgroundIndexingTests: XCTestCase {
707716
_ = try await project.testClient.send(BarrierRequest())
708717
_ = try project.openDocument("LibD.swift")
709718

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+
710722
allDocumentsOpened.signal()
711723
try libDPreparedForEditing.waitOrThrow()
712724
}

0 commit comments

Comments
 (0)