Skip to content

Make fulfillmentOfOrThrow take a variadic list of expectations #2084

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 25, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/SKTestSupport/Assertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ package struct ExpectationNotFulfilledError: Error, CustomStringConvertible {
/// Wait for the given expectations to be fulfilled. If the expectations aren't
/// fulfilled within `timeout`, throw an error, aborting the test execution.
package nonisolated func fulfillmentOfOrThrow(
_ expectations: [XCTestExpectation],
_ expectations: XCTestExpectation...,
timeout: TimeInterval = defaultTimeout,
enforceOrder enforceOrderOfFulfillment: Bool = false
) async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class BuildSystemManagerTests: XCTestCase {
(a, .swift, fallbackBuildSettings(for: a, language: .swift, options: .init()), changed)
])
await buildSystem.setBuildSettings(for: a, to: nil)
try await fulfillmentOfOrThrow([changed])
try await fulfillmentOfOrThrow(changed)
}

func testSettingsMainFileInitialNil() async throws {
Expand All @@ -187,7 +187,7 @@ final class BuildSystemManagerTests: XCTestCase {
let changed = expectation(description: "changed settings")
await del.setExpected([(a, .swift, FileBuildSettings(compilerArguments: ["x"], language: .swift), changed)])
await buildSystem.setBuildSettings(for: a, to: TextDocumentSourceKitOptionsResponse(compilerArguments: ["x"]))
try await fulfillmentOfOrThrow([changed])
try await fulfillmentOfOrThrow(changed)
}

func testSettingsMainFileWithFallback() async throws {
Expand All @@ -211,12 +211,12 @@ final class BuildSystemManagerTests: XCTestCase {
for: a,
to: TextDocumentSourceKitOptionsResponse(compilerArguments: ["non-fallback", "args"])
)
try await fulfillmentOfOrThrow([changed])
try await fulfillmentOfOrThrow(changed)

let revert = expectation(description: "revert to fallback settings")
await del.setExpected([(a, .swift, fallbackSettings, revert)])
await buildSystem.setBuildSettings(for: a, to: nil)
try await fulfillmentOfOrThrow([revert])
try await fulfillmentOfOrThrow(revert)
}

func testSettingsHeaderChangeMainFile() async throws {
Expand Down Expand Up @@ -257,20 +257,20 @@ final class BuildSystemManagerTests: XCTestCase {
let changed = expectation(description: "changed settings to cpp2")
await del.setExpected([(h, .c, FileBuildSettings(compilerArguments: ["C++ 2"], language: .c), changed)])
await manager.mainFilesChanged()
try await fulfillmentOfOrThrow([changed])
try await fulfillmentOfOrThrow(changed)

let changed2 = expectation(description: "still cpp2, no update")
changed2.isInverted = true
await del.setExpected([(h, .c, nil, changed2)])
await manager.mainFilesChanged()
try await fulfillmentOfOrThrow([changed2], timeout: 1)
try await fulfillmentOfOrThrow(changed2, timeout: 1)

await mainFiles.updateMainFiles(for: h, to: [cpp1, cpp2])

let changed3 = expectation(description: "added lexicographically earlier main file")
await del.setExpected([(h, .c, FileBuildSettings(compilerArguments: ["C++ 1"], language: .c), changed3)])
await manager.mainFilesChanged()
try await fulfillmentOfOrThrow([changed3], timeout: 1)
try await fulfillmentOfOrThrow(changed3, timeout: 1)

await mainFiles.updateMainFiles(for: h, to: [])

Expand All @@ -279,7 +279,7 @@ final class BuildSystemManagerTests: XCTestCase {
(h, .c, fallbackBuildSettings(for: h, language: .cpp, options: .init()), changed4)
])
await manager.mainFilesChanged()
try await fulfillmentOfOrThrow([changed4])
try await fulfillmentOfOrThrow(changed4)
}

func testSettingsOneMainTwoHeader() async throws {
Expand Down Expand Up @@ -332,7 +332,7 @@ final class BuildSystemManagerTests: XCTestCase {
for: cpp,
to: TextDocumentSourceKitOptionsResponse(compilerArguments: [newCppArg, cpp.pseudoPath])
)
try await fulfillmentOfOrThrow([changed1, changed2])
try await fulfillmentOfOrThrow(changed1, changed2)
}
}

Expand Down
24 changes: 12 additions & 12 deletions Tests/LanguageServerProtocolJSONRPCTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ConnectionTests: XCTestCase {
expectation.fulfill()
}

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testMessageBuffer() async throws {
Expand Down Expand Up @@ -81,7 +81,7 @@ class ConnectionTests: XCTestCase {
_rawData: [notification1Str.utf8.last!, notfication2Str.utf8.first!].withUnsafeBytes { DispatchData(bytes: $0) }
)

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)

let expectation2 = self.expectation(description: "notification received")

Expand All @@ -94,7 +94,7 @@ class ConnectionTests: XCTestCase {
clientConnection.send(_rawData: [b].withUnsafeBytes { DispatchData(bytes: $0) })
}

try await fulfillmentOfOrThrow([expectation2])
try await fulfillmentOfOrThrow(expectation2)

// Close the connection before accessing requestBuffer, which ensures we don't race.
connection.serverToClientConnection.close()
Expand All @@ -120,7 +120,7 @@ class ConnectionTests: XCTestCase {
expectation2.fulfill()
}

try await fulfillmentOfOrThrow([expectation, expectation2])
try await fulfillmentOfOrThrow(expectation, expectation2)
}

func testEchoNotification() async throws {
Expand All @@ -134,7 +134,7 @@ class ConnectionTests: XCTestCase {

client.send(EchoNotification(string: "hello!"))

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testUnknownRequest() async throws {
Expand All @@ -151,7 +151,7 @@ class ConnectionTests: XCTestCase {
expectation.fulfill()
}

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testUnknownNotification() async throws {
Expand All @@ -173,7 +173,7 @@ class ConnectionTests: XCTestCase {
expectation.fulfill()
}

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testUnexpectedResponse() async throws {
Expand All @@ -192,7 +192,7 @@ class ConnectionTests: XCTestCase {
expectation.fulfill()
}

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testSendAfterClose() async throws {
Expand All @@ -212,7 +212,7 @@ class ConnectionTests: XCTestCase {
connection.clientToServerConnection.close()
connection.clientToServerConnection.close()

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testSendBeforeClose() async throws {
Expand All @@ -227,7 +227,7 @@ class ConnectionTests: XCTestCase {
server.client.send(EchoNotification(string: "about to close!"))
connection.serverToClientConnection.close()

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

/// We can explicitly close a connection, but the connection also
Expand Down Expand Up @@ -279,7 +279,7 @@ class ConnectionTests: XCTestCase {
#endif
conn.close()

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
withExtendedLifetime(conn) {}
}
}
Expand All @@ -300,7 +300,7 @@ class ConnectionTests: XCTestCase {
"""
connection.clientToServerConnection.send(message: messageContents)

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/LanguageServerProtocolTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ConnectionTests: XCTestCase {
expectation.fulfill()
}

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}

func testEchoError() async throws {
Expand All @@ -57,7 +57,7 @@ class ConnectionTests: XCTestCase {
expectation2.fulfill()
}

try await fulfillmentOfOrThrow([expectation, expectation2])
try await fulfillmentOfOrThrow(expectation, expectation2)
}

func testEchoNotification() async throws {
Expand All @@ -71,6 +71,6 @@ class ConnectionTests: XCTestCase {

client.send(EchoNotification(string: "hello!"))

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}
}
2 changes: 1 addition & 1 deletion Tests/SKLoggingTests/LoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class LoggingTests: XCTestCase {
}
)
logger.log(level: .error, "my message")
try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
XCTAssert(
message.starts(with: "[org.swift.sourcekit-lsp:test] error"),
"Message did not have expected header. Received \n\(message)"
Expand Down
4 changes: 2 additions & 2 deletions Tests/SKUtilitiesTests/DebouncerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class DebouncerTests: XCTestCase {
}
await debouncer.scheduleCall()
await debouncer.scheduleCall()
try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
// Sleep for 0.2s to make sure the debouncer actually debounces and doesn't fulfill the expectation twice.
try await Task.sleep(for: .seconds(0.2))
}
Expand All @@ -37,6 +37,6 @@ final class DebouncerTests: XCTestCase {
}
await debouncer.scheduleCall(1)
await debouncer.scheduleCall(2)
try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)
}
}
14 changes: 7 additions & 7 deletions Tests/SemanticIndexTests/TaskSchedulerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,17 @@ final class TaskSchedulerTests: XCTestCase {
}

// The high priority task should be able to finish because we have an execution slot for it.
try await fulfillmentOfOrThrow([highPriorityTaskFinished])
try await fulfillmentOfOrThrow(highPriorityTaskFinished)

// But we shouldn't be able to execute the low priority task because it doesn't have an execution slot.
await assertThrowsError(try await fulfillmentOfOrThrow([lowPriorityTaskFinished1], timeout: 1)) { error in
await assertThrowsError(try await fulfillmentOfOrThrow(lowPriorityTaskFinished1, timeout: 1)) { error in
XCTAssert(error is ExpectationNotFulfilledError)
}

await taskScheduler.setMaxConcurrentTasksByPriority([(.high, 1), (.low, 1)])

// After increasing the number of execution slots, we should be able to execute the low-priority task
try await fulfillmentOfOrThrow([lowPriorityTaskFinished2])
try await fulfillmentOfOrThrow(lowPriorityTaskFinished2)
}

func testDecreaseNumberOfExecutionSlots() async throws {
Expand All @@ -261,7 +261,7 @@ final class TaskSchedulerTests: XCTestCase {
taskStartedExecuting.fulfill()

do {
try await fulfillmentOfOrThrow([executionSlotsReduced])
try await fulfillmentOfOrThrow(executionSlotsReduced)

try await repeatUntilExpectedResult {
try Task.checkCancellation()
Expand All @@ -276,14 +276,14 @@ final class TaskSchedulerTests: XCTestCase {
}

// Check that we cancel the in-progress task when reducing the number of execution slots
try await fulfillmentOfOrThrow([taskStartedExecuting])
try await fulfillmentOfOrThrow(taskStartedExecuting)
await taskScheduler.setMaxConcurrentTasksByPriority([(.low, 0)])
executionSlotsReduced.fulfill()
try await fulfillmentOfOrThrow([taskCancelled])
try await fulfillmentOfOrThrow(taskCancelled)

// And check that we execute it again when increasing the number of execution slots again
await taskScheduler.setMaxConcurrentTasksByPriority([(.low, 1)])
try await fulfillmentOfOrThrow([taskExecutedAgain])
try await fulfillmentOfOrThrow(taskExecutedAgain)
}

func testUseAllExecutionSlotsWithHighAndLowPriorityTasks() async throws {
Expand Down
10 changes: 5 additions & 5 deletions Tests/SourceKitDTests/CrashRecoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ final class CrashRecoveryTests: XCTestCase {

await clangdServer.crash()

try await fulfillmentOfOrThrow([clangdCrashed])
try await fulfillmentOfOrThrow([clangdRestarted])
try await fulfillmentOfOrThrow(clangdCrashed)
try await fulfillmentOfOrThrow(clangdRestarted)
}

func testClangdCrashRecovery() async throws {
Expand Down Expand Up @@ -298,15 +298,15 @@ final class CrashRecoveryTests: XCTestCase {

await clangdServer.crash()

try await fulfillmentOfOrThrow([clangdCrashed], timeout: 5)
try await fulfillmentOfOrThrow([clangdRestartedFirstTime], timeout: 30)
try await fulfillmentOfOrThrow(clangdCrashed, timeout: 5)
try await fulfillmentOfOrThrow(clangdRestartedFirstTime, timeout: 30)
// Clangd has restarted. Note the date so we can check that the second restart doesn't happen too quickly.
let firstRestartDate = Date()

// Crash clangd again. This time, it should only restart after a delay.
await clangdServer.crash()

try await fulfillmentOfOrThrow([clangdRestartedSecondTime], timeout: 30)
try await fulfillmentOfOrThrow(clangdRestartedSecondTime, timeout: 30)
XCTAssert(
Date().timeIntervalSince(firstRestartDate) > 5,
"Clangd restarted too quickly after crashing twice in a row. We are not preventing crash loops."
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitDTests/SourceKitDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class SourceKitDTests: XCTestCase {

_ = try await sourcekitd.send(req, timeout: defaultTimeoutDuration, fileContents: nil)

try await fulfillmentOfOrThrow([expectation1, expectation2])
try await fulfillmentOfOrThrow(expectation1, expectation2)

let close = sourcekitd.dictionary([
keys.request: sourcekitd.requests.editorClose,
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ final class BackgroundIndexingTests: XCTestCase {
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
)

try await fulfillmentOfOrThrow([receivedEmptyDiagnostics])
try await fulfillmentOfOrThrow(receivedEmptyDiagnostics)

// Check that we received a work done progress for the re-preparation of the target
_ = try await project.testClient.nextNotification(
Expand Down Expand Up @@ -2618,7 +2618,7 @@ final class BackgroundIndexingTests: XCTestCase {
func myTestFunc() {}
"""
)
try await fulfillmentOfOrThrow([updateIndexStoreStarted])
try await fulfillmentOfOrThrow(updateIndexStoreStarted)
try await repeatUntilExpectedResult(sleepInterval: .milliseconds(2)) {
try await !project.testClient.send(IsIndexingRequest()).indexing
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/CodeActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ final class CodeActionTests: XCTestCase {
}
_ = try await testClient.send(ExecuteCommandRequest(command: command.command, arguments: command.arguments))

try await fulfillmentOfOrThrow([editReceived])
try await fulfillmentOfOrThrow(editReceived)
}

func testAddDocumentationCodeActionResult() async throws {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/DefinitionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ class DefinitionTests: XCTestCase {
diagnosticRefreshRequestReceived.fulfill()
return VoidResponse()
}
try await fulfillmentOfOrThrow([diagnosticRefreshRequestReceived])
try await fulfillmentOfOrThrow(diagnosticRefreshRequestReceived)

let afterChangingFileA = try await project.testClient.send(
DefinitionRequest(textDocument: TextDocumentIdentifier(bUri), position: bPositions["1️⃣"])
Expand Down Expand Up @@ -438,7 +438,7 @@ class DefinitionTests: XCTestCase {
diagnosticRefreshRequestReceived.fulfill()
return VoidResponse()
}
try await fulfillmentOfOrThrow([diagnosticRefreshRequestReceived])
try await fulfillmentOfOrThrow(diagnosticRefreshRequestReceived)

let afterBuilding = try await project.testClient.send(
DefinitionRequest(textDocument: TextDocumentIdentifier(bUri), position: bPositions["2️⃣"])
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/ExecuteCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class ExecuteCommandTests: XCTestCase {

let _ = try await testClient.send(request)

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)

let label = try XCTUnwrap(applyEditTitle.value)
let edit = try XCTUnwrap(applyEditWorkspaceEdit.value)
Expand Down Expand Up @@ -124,7 +124,7 @@ final class ExecuteCommandTests: XCTestCase {

let _ = try await testClient.send(request)

try await fulfillmentOfOrThrow([expectation])
try await fulfillmentOfOrThrow(expectation)

let label = try XCTUnwrap(applyEditTitle.value)
let edit = try XCTUnwrap(applyEditWorkspaceEdit.value)
Expand Down
Loading