Skip to content
Open
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
8 changes: 6 additions & 2 deletions Sources/SecureXPC/SequentialResultProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,12 @@ public class SequentialResultProvider<S: Encodable> {
do {
try encodingWork(&response)
if let deliveryHandler = deliveryHandler {
xpc_connection_send_message_with_reply(connection, response, nil) { _ in
deliveryHandler(.success(()))
xpc_connection_send_message_with_reply(connection, response, nil) { result in
if xpc_get_type(result) == XPC_TYPE_ERROR {
deliveryHandler(.failure(XPCError.fromXPCObject(result)))
} else {
deliveryHandler(.success(()))
}
}
} else {
xpc_connection_send_message(connection, response)
Expand Down
18 changes: 14 additions & 4 deletions Tests/SecureXPCTests/Client & Server/Sequential Result Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ class SequentialResultTests: XCTestCase {
}
}

let expectation = self.expectation(description: "The second sequence value won't be decodable")
let secondSequenceValueNotDecodableExpectation = self.expectation(description: "The second sequence value won't be decodable")
let thirdSequenceValueSentExpectation = self.expectation(description: "Attempted to send third sequence value")
enum ExampleError: Error, Codable {
case didNotWork
}
Expand All @@ -325,10 +326,19 @@ class SequentialResultTests: XCTestCase {
do {
try await provider.success(value: .noValue)
try await provider.success(value: .alwaysFailedDecode(NotActuallyDecodable()))
try await provider.success(value: .noValue)
} catch {
XCTFail("Unexpected error: \(error)")
}
do {
try await provider.success(value: .noValue)
XCTFail("Sending the third reply should fail with an XPCError.connectionInterrupted error")
}
catch XPCError.connectionInterrupted {
// Expected error
} catch {
XCTFail("Unexpected error: \(error)")
}
thirdSequenceValueSentExpectation.fulfill()
}

let sequence = client.send(to: route)
Expand All @@ -340,10 +350,10 @@ class SequentialResultTests: XCTestCase {
_ = try await iterator.next()
} catch {
if case XPCError.decodingError(_) = error {
expectation.fulfill()
secondSequenceValueNotDecodableExpectation.fulfill()
}
}

await self.waitForExpectations(timeout: 1)
}

Expand Down