Skip to content

Fix non-deterministic test failure in BackgroundIndexingTests.testPrepareTarget #1317

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 1 commit into from
May 20, 2024
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
31 changes: 17 additions & 14 deletions Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,27 +554,30 @@ final class BackgroundIndexingTests: XCTestCase {
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: try project.uri(for: "MyFile.swift"), type: .changed)])
)

let diagnosticRefreshReceived = self.expectation(description: "Received diagnostic refresh request")
project.testClient.handleNextRequest { (_: DiagnosticsRefreshRequest) in
diagnosticRefreshReceived.fulfill()
return VoidResponse()
}

// Send a document request for `uri` to trigger re-preparation of its target. We don't actually care about the
// response for this request. Instead, we wait until SourceKit-LSP sends us a `DiagnosticsRefreshRequest`,
// indicating that the target of `uri` has been prepared.
_ = try await project.testClient.send(
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
)
try await fulfillmentOfOrThrow([diagnosticRefreshReceived])

let updatedDiagnostics = try await project.testClient.send(
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
)
guard case .full(let updatedDiagnostics) = updatedDiagnostics else {
XCTFail("Expected full diagnostics")
return
let receivedEmptyDiagnostics = self.expectation(description: "Received diagnostic refresh request")
project.testClient.handleNextRequest { (_: DiagnosticsRefreshRequest) in
Task {
let updatedDiagnostics = try await project.testClient.send(
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
)
guard case .full(let updatedDiagnostics) = updatedDiagnostics else {
XCTFail("Expected full diagnostics")
return
}
if updatedDiagnostics.items.isEmpty {
receivedEmptyDiagnostics.fulfill()
}
}
return VoidResponse()
}
XCTAssertEqual(updatedDiagnostics.items, [])

try await fulfillmentOfOrThrow([receivedEmptyDiagnostics])
}
}