Skip to content

Commit 4d34d30

Browse files
committed
Wait for asynchronous setup in BuildSystemTests using an expecatation instead of a semaphore
Just cleaner because it will also fail if it times out.
1 parent fbd0cd1 commit 4d34d30

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Tests/SourceKitLSPTests/BuildSystemTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ final class BuildSystemTests: XCTestCase {
9292
// hackery to synchronously wait for a task to finish. This is very much an
9393
// anti-pattern because it can easily lead to priority inversions and should
9494
// thus not be copied to any non-test code.
95-
let sema = DispatchSemaphore(value: 0)
95+
let setUpCompleted = XCTestExpectation(description: "Waiting for set up")
9696
Task {
9797
haveClangd = ToolchainRegistry.shared.toolchains.contains { $0.clangd != nil }
9898
testServer = TestSourceKitServer()
@@ -123,9 +123,11 @@ final class BuildSystemTests: XCTestCase {
123123
capabilities: ClientCapabilities(workspace: nil, textDocument: nil),
124124
trace: .off,
125125
workspaceFolders: nil))
126-
sema.signal()
126+
setUpCompleted.fulfill()
127+
}
128+
if XCTWaiter.wait(for: [setUpCompleted], timeout: defaultTimeout) != .completed {
129+
XCTFail("Set up failed to complete")
127130
}
128-
sema.wait()
129131
}
130132

131133
override func tearDown() {

0 commit comments

Comments
 (0)