Skip to content

Commit b8d4c62

Browse files
authored
Merge pull request #1499 from ahoppen/fix-dont-stack-preparation-test
Fix a nondeterministic test failure of `testDontStackTargetPreparationForEditorFunctionality`
2 parents e75fac5 + 7806cfe commit b8d4c62

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
@@ -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

Comments
 (0)