Skip to content

Commit 323046f

Browse files
authored
Merge pull request #1782 from ahoppen/diagnostic-timeout-repeat
Fix nondeterministic test failure for tests that await next diagnostic notification
2 parents 57f92b6 + b52fb91 commit 323046f

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)