From e303360b910cd2f7f80896d044ed7b67e55ce50a Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 13 Nov 2024 17:57:37 -0800 Subject: [PATCH] Fix issue where test nondeterministically failed if SwiftPM doesn't return build settings quickly We might not have build settings at the time when we get the first diagnostics notification here and thus might get syntactic fallback diagnostics that don't contain 'Cannot find ... in scope' --- .../SourceKitLSPTests/PublishDiagnosticsTests.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Tests/SourceKitLSPTests/PublishDiagnosticsTests.swift b/Tests/SourceKitLSPTests/PublishDiagnosticsTests.swift index 04c00e219..7d55759d8 100644 --- a/Tests/SourceKitLSPTests/PublishDiagnosticsTests.swift +++ b/Tests/SourceKitLSPTests/PublishDiagnosticsTests.swift @@ -137,10 +137,14 @@ final class PublishDiagnosticsTests: XCTestCase { ) _ = try project.openDocument("FileB.swift") - let diagnosticsBeforeChangingFileA = try await project.testClient.nextDiagnosticsNotification() - XCTAssert( - diagnosticsBeforeChangingFileA.diagnostics.contains(where: { $0.message == "Cannot find 'sayHello' in scope" }) - ) + try await repeatUntilExpectedResult { + let diagnostics = try await project.testClient.nextDiagnosticsNotification() + if diagnostics.diagnostics.contains(where: { $0.message == "Cannot find 'sayHello' in scope" }) { + return true + } + logger.debug("Received unexpected diagnostics: \(diagnostics.forLogging)") + return false + } let updatedACode = "func sayHello() {}" let aUri = try project.uri(for: "FileA.swift")