Skip to content

Commit b5296dc

Browse files
committed
Fix a nondeterministic test failure of testDontStackTargetPreparationForEditorFunctionality
We fulfilled the `allDocumentsOpened` expectation directly after dispatching the notification to open LibD.swift. This left a very short window in which LibB’s preparation could finish and LibC’s expectation could start before the open notification for LibD.swift was handled, causing an unexpected preparation of LibC. This fixes the issue first reported as rdar://129698768 and for which I added logging in #1478. # Conflicts: # Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
1 parent c557f16 commit b5296dc

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
@@ -692,7 +692,16 @@ final class BackgroundIndexingTests: XCTestCase {
692692
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: try project.uri(for: "LibA.swift"), type: .changed)])
693693
)
694694

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

@@ -704,6 +713,9 @@ final class BackgroundIndexingTests: XCTestCase {
704713
_ = try await project.testClient.send(BarrierRequest())
705714
_ = try project.openDocument("LibD.swift")
706715

716+
// Send a barrier request to ensure we have finished opening LibD before allowing the preparation of LibB to finish.
717+
_ = try await project.testClient.send(BarrierRequest())
718+
707719
allDocumentsOpened.fulfill()
708720
try await self.fulfillmentOfOrThrow([libDPreparedForEditing])
709721
}

0 commit comments

Comments
 (0)