Skip to content

Fix nondeterministic failure in testSyntacticOrIndexBasedXCTestsBasedOnWhetherFileIsIndexed #2037

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
Mar 6, 2025
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
15 changes: 15 additions & 0 deletions Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import Foundation
import LanguageServerProtocol
import SKTestSupport
import SemanticIndex
@_spi(Testing) import SourceKitLSP
import SwiftExtensions
import ToolchainRegistry
Expand Down Expand Up @@ -113,6 +114,9 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
func testSyntacticOrIndexBasedXCTestsBasedOnWhetherFileIsIndexed() async throws {
try SkipUnless.longTestsEnabled()

let initialIndexingFinished = AtomicBool(initialValue: false)
let syntacticWorkspaceRequestSent = WrappedSemaphore(name: "Syntactic workspace request sent")

let project = try await SwiftPMTestProject(
files: [
"Tests/MyLibraryTests/MyTests.swift": """
Expand All @@ -126,9 +130,18 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
"""
],
manifest: packageManifestWithTestTarget,
hooks: Hooks(
indexHooks: IndexHooks(updateIndexStoreTaskDidStart: { _ in
if initialIndexingFinished.value {
syntacticWorkspaceRequestSent.waitOrXCTFail()
}
})
),
enableBackgroundIndexing: true
)

initialIndexingFinished.value = true

let myTestsUri = try project.uri(for: "MyTests.swift")

// First get the tests from the original file contents, which are computed by the semantic index.
Expand Down Expand Up @@ -200,6 +213,8 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
]
)

syntacticWorkspaceRequestSent.signal()

// After building again, we should have updated the updated the semantic index and realize that `NotQuiteTests` does
// not inherit from XCTest and thus doesn't have any test methods.

Expand Down