Skip to content

Commit 375f9e5

Browse files
authored
Merge pull request #2037 from ahoppen/flaky-workspacetestdiscovery-test
Fix nondeterministic failure in `testSyntacticOrIndexBasedXCTestsBasedOnWhetherFileIsIndexed`
2 parents 2a12d21 + 9184f65 commit 375f9e5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import Foundation
1515
import LanguageServerProtocol
1616
import SKTestSupport
17+
import SemanticIndex
1718
@_spi(Testing) import SourceKitLSP
1819
import SwiftExtensions
1920
import ToolchainRegistry
@@ -113,6 +114,9 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
113114
func testSyntacticOrIndexBasedXCTestsBasedOnWhetherFileIsIndexed() async throws {
114115
try SkipUnless.longTestsEnabled()
115116

117+
let initialIndexingFinished = AtomicBool(initialValue: false)
118+
let syntacticWorkspaceRequestSent = WrappedSemaphore(name: "Syntactic workspace request sent")
119+
116120
let project = try await SwiftPMTestProject(
117121
files: [
118122
"Tests/MyLibraryTests/MyTests.swift": """
@@ -126,9 +130,18 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
126130
"""
127131
],
128132
manifest: packageManifestWithTestTarget,
133+
hooks: Hooks(
134+
indexHooks: IndexHooks(updateIndexStoreTaskDidStart: { _ in
135+
if initialIndexingFinished.value {
136+
syntacticWorkspaceRequestSent.waitOrXCTFail()
137+
}
138+
})
139+
),
129140
enableBackgroundIndexing: true
130141
)
131142

143+
initialIndexingFinished.value = true
144+
132145
let myTestsUri = try project.uri(for: "MyTests.swift")
133146

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

216+
syntacticWorkspaceRequestSent.signal()
217+
203218
// After building again, we should have updated the updated the semantic index and realize that `NotQuiteTests` does
204219
// not inherit from XCTest and thus doesn't have any test methods.
205220

0 commit comments

Comments
 (0)