Skip to content
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
27 changes: 6 additions & 21 deletions Sources/GRPCCore/Configuration/MethodConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,21 +393,6 @@ private func validateMaxAttempts(_ value: Int) throws -> Int {
return min(value, 5)
}

extension Duration {
fileprivate init(googleProtobufDuration duration: String) throws {
guard duration.utf8.last == UInt8(ascii: "s"),
let fractionalSeconds = Double(duration.dropLast())
else {
throw RuntimeError(code: .invalidArgument, message: "Invalid google.protobuf.duration")
}

let seconds = fractionalSeconds.rounded(.down)
let attoseconds = (fractionalSeconds - seconds) / 1e18

self.init(secondsComponent: Int64(seconds), attosecondsComponent: Int64(attoseconds))
}
}

extension MethodConfig: Codable {
private enum CodingKeys: String, CodingKey {
case name
Expand Down Expand Up @@ -506,12 +491,12 @@ extension RetryPolicy: Codable {
let maxAttempts = try container.decode(Int.self, forKey: .maxAttempts)
self.maxAttempts = try validateMaxAttempts(maxAttempts)

let initialBackoff = try container.decode(String.self, forKey: .initialBackoff)
self.initialBackoff = try Duration(googleProtobufDuration: initialBackoff)
let initialBackoff = try container.decode(GoogleProtobufDuration.self, forKey: .initialBackoff)
self.initialBackoff = initialBackoff.duration
try Self.validateInitialBackoff(self.initialBackoff)

let maxBackoff = try container.decode(String.self, forKey: .maxBackoff)
self.maxBackoff = try Duration(googleProtobufDuration: maxBackoff)
let maxBackoff = try container.decode(GoogleProtobufDuration.self, forKey: .maxBackoff)
self.maxBackoff = maxBackoff.duration
try Self.validateMaxBackoff(self.maxBackoff)

self.backoffMultiplier = try container.decode(Double.self, forKey: .backoffMultiplier)
Expand Down Expand Up @@ -551,8 +536,8 @@ extension HedgingPolicy: Codable {
let maxAttempts = try container.decode(Int.self, forKey: .maxAttempts)
self.maxAttempts = try validateMaxAttempts(maxAttempts)

let delay = try container.decode(String.self, forKey: .hedgingDelay)
self.hedgingDelay = try Duration(googleProtobufDuration: delay)
let delay = try container.decode(GoogleProtobufDuration.self, forKey: .hedgingDelay)
self.hedgingDelay = delay.duration

let statusCodes = try container.decode([GoogleRPCCode].self, forKey: .nonFatalStatusCodes)
self.nonFatalStatusCodes = Set(statusCodes.map { $0.code })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ struct ServerCancellationManagerTests {
@Test("Remove cancellation handler")
func removeCancellationHandler() async throws {
let manager = ServerCancellationManager()
let signal = AsyncStream.makeStream(of: Void.self)

let id = manager.addRPCCancelledHandler {
Issue.record("Unexpected cancellation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct MethodConfigCodingTests {
("1s", .seconds(1)),
("1.000000s", .seconds(1)),
("0s", .zero),
("0.1s", .milliseconds(100)),
("100.123s", .milliseconds(100_123)),
] as [(String, Duration)]
)
Expand Down
Loading