Skip to content

Commit

Permalink
Add wait-for-ready to method config (#1850)
Browse files Browse the repository at this point in the history
Motivation:

The wait-for-ready property was missing from method config.

Modifications:

- Add wait-for-ready property and parsing

Result:

wait-for-ready is available in method config
  • Loading branch information
glbrntt authored Apr 3, 2024
1 parent f84657d commit 78a20cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/GRPCCore/Configuration/MethodConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public struct MethodConfiguration: Hashable, Sendable {
/// The names of methods which this configuration applies to.
public var names: [Name]

/// Whether RPCs for this method should wait until the connection is ready.
///
/// If `false` the RPC will abort immediately if there is a transient failure connecting to
/// the server. Otherwise gRPC will attempt to connect until the deadline is exceeded.
public var waitForReady: Bool?

/// The default timeout for the RPC.
///
/// If no reply is received in the specified amount of time the request is aborted
Expand Down Expand Up @@ -112,18 +118,21 @@ public struct MethodConfiguration: Hashable, Sendable {
///
/// - Parameters:
/// - names: The names of methods this configuration applies to.
/// - waitForReady: Whether RPCs sent to this method should wait until the connection is ready.
/// - timeout: The default timeout for the RPC.
/// - maxRequestMessageBytes: The maximum allowed size of a request message in bytes.
/// - maxResponseMessageBytes: The maximum allowed size of a response message in bytes.
/// - executionPolicy: The execution policy to use for the RPC.
public init(
names: [Name],
waitForReady: Bool? = nil,
timeout: Duration? = nil,
maxRequestMessageBytes: Int? = nil,
maxResponseMessageBytes: Int? = nil,
executionPolicy: ExecutionPolicy? = nil
) {
self.names = names
self.waitForReady = waitForReady
self.timeout = timeout
self.maxRequestMessageBytes = maxRequestMessageBytes
self.maxResponseMessageBytes = maxResponseMessageBytes
Expand Down Expand Up @@ -367,6 +376,7 @@ extension Duration {
extension MethodConfiguration: Codable {
private enum CodingKeys: String, CodingKey {
case name
case waitForReady
case timeout
case maxRequestMessageBytes
case maxResponseMessageBytes
Expand All @@ -378,6 +388,9 @@ extension MethodConfiguration: Codable {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.names = try container.decode([Name].self, forKey: .name)

let waitForReady = try container.decodeIfPresent(Bool.self, forKey: .waitForReady)
self.waitForReady = waitForReady

let timeout = try container.decodeIfPresent(GoogleProtobufDuration.self, forKey: .timeout)
self.timeout = timeout?.duration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ internal final class MethodConfigurationCodingTests: XCTestCase {
}
]

$0.waitForReady = true

$0.timeout = .with {
$0.seconds = 1
$0.nanos = 0
Expand All @@ -364,6 +366,7 @@ internal final class MethodConfigurationCodingTests: XCTestCase {
let jsonConfig = try config.jsonUTF8Data()
let decoded = try self.decoder.decode(MethodConfiguration.self, from: jsonConfig)
XCTAssertEqual(decoded.names, [MethodConfiguration.Name(service: "echo.Echo", method: "Get")])
XCTAssertEqual(decoded.waitForReady, true)
XCTAssertEqual(decoded.timeout, Duration(secondsComponent: 1, attosecondsComponent: 0))
XCTAssertEqual(decoded.maxRequestMessageBytes, 1024)
XCTAssertEqual(decoded.maxResponseMessageBytes, 2048)
Expand Down

0 comments on commit 78a20cb

Please sign in to comment.