Skip to content

Commit b52fb91

Browse files
committed
Fix nondeterministic test failure for tests that await next diagnostic notification
These tests were designed to poll for the next diagnostic notification and if that notification didn’t contain the expected result, try again. But if we didn’t get any diagnostic notification in 1s, we would unconditionally fail instead of trying again, which was not intended.
1 parent 9e9579d commit b52fb91

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Tests/SourceKitLSPTests/BuildSystemTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ final class BuildSystemTests: XCTestCase {
120120
await buildSystem.setBuildSettings(for: doc, to: newSettings)
121121

122122
try await repeatUntilExpectedResult {
123-
let refreshedDiags = try await testClient.nextDiagnosticsNotification(timeout: .seconds(1))
123+
guard let refreshedDiags = try? await testClient.nextDiagnosticsNotification(timeout: .seconds(1)) else {
124+
return false
125+
}
124126
return try text == documentManager.latestSnapshot(doc).text && refreshedDiags.diagnostics.count == 0
125127
}
126128
}

Tests/SourceKitLSPTests/MainFilesProviderTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ final class MainFilesProviderTests: XCTestCase {
195195
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: fancyLibraryUri, type: .changed)])
196196
)
197197

198-
// 'MyFancyLibrary.c' now also includes 'shared.h'. Since it lexicographically preceeds MyLibrary, we should use its
198+
// 'MyFancyLibrary.c' now also includes 'shared.h'. Since it lexicographically precedes MyLibrary, we should use its
199199
// build settings.
200200
// `clangd` may return diagnostics from the old build settings sometimes (I believe when it's still building the
201201
// preamble for shared.h when the new build settings come in). Check that it eventually returns the correct
202202
// diagnostics.
203203
try await repeatUntilExpectedResult {
204-
let refreshedDiags = try await project.testClient.nextDiagnosticsNotification(timeout: .seconds(1))
205-
guard let diagnostic = refreshedDiags.diagnostics.only else {
204+
let refreshedDiags = try? await project.testClient.nextDiagnosticsNotification(timeout: .seconds(1))
205+
guard let diagnostic = refreshedDiags?.diagnostics.only else {
206206
return false
207207
}
208208
return diagnostic.message == "Unused variable 'fromMyFancyLibrary'"

0 commit comments

Comments
 (0)