Skip to content

[6.0] Fix a nondeterministic test failure of testDontStackTargetPreparationForEditorFunctionality #1504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,16 @@ final class BackgroundIndexingTests: XCTestCase {
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: try project.uri(for: "LibA.swift"), type: .changed)])
)

// Quickly flip through all files
// Quickly flip through all files. The way the test is designed to work is as follows:
// - LibB.swift gets opened and prepared. Preparation is simulated to take a long time until both LibC.swift and
// LibD.swift have been opened.
// - LibC.swift gets opened. This queues preparation of LibC but doesn't cancel preparation of LibB because we
// don't cancel in-progress preparation tasks to guarantee forward progress (see comment at the end of
// `SemanticIndexManager.prepare`).
// - Now LibD.swift gets opened. This cancels preparation of LibC which actually cancels LibC's preparation for
// real because LibC's preparation hasn't started yet (it's only queued).
// Thus, the only targets that are being prepared are LibB and LibD, which is checked by the
// `ExpectedIndexTaskTracker`.
_ = try project.openDocument("LibB.swift")
try libBStartedPreparation.waitOrThrow()

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

// Send a barrier request to ensure we have finished opening LibD before allowing the preparation of LibB to finish.
_ = try await project.testClient.send(BarrierRequest())

allDocumentsOpened.signal()
try libDPreparedForEditing.waitOrThrow()
}
Expand Down