refactor: address review feedback on retry_delay (#19)
All checks were successful
Rust / check (pull_request) Successful in 2m42s
All checks were successful
Rust / check (pull_request) Successful in 2m42s
- Drop the unreachable checked_mul in parse_duration; a fraction of at most 9 digits scaled to nanoseconds always fits in a u32. - Share a vertex_error test helper in error.rs instead of building VertexApiError inline. - Bump version to 0.2.0 for the breaking VertexApiError.details change.
This commit is contained in:
29
src/error.rs
29
src/error.rs
@@ -116,16 +116,18 @@ impl Error {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn vertex_error(code: i32, status: &str, details: Option<Vec<serde_json::Value>>) -> Error {
|
||||
Error::VertexError(types::VertexApiError {
|
||||
code,
|
||||
message: "test".to_string(),
|
||||
status: status.to_string(),
|
||||
details,
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vertex_error_retryable_classification() {
|
||||
let make_err = |code: i32, status: &str| {
|
||||
Error::VertexError(types::VertexApiError {
|
||||
code,
|
||||
message: "test".to_string(),
|
||||
status: status.to_string(),
|
||||
details: None,
|
||||
})
|
||||
};
|
||||
let make_err = |code: i32, status: &str| vertex_error(code, status, None);
|
||||
|
||||
// Retryable codes
|
||||
assert!(make_err(429, "TOO_MANY_REQUESTS").is_retryable());
|
||||
@@ -167,15 +169,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn retry_delay_delegates_to_vertex_error() {
|
||||
let err = Error::VertexError(types::VertexApiError {
|
||||
code: 429,
|
||||
message: "Quota exceeded".to_string(),
|
||||
status: "RESOURCE_EXHAUSTED".to_string(),
|
||||
details: Some(vec![serde_json::json!({
|
||||
let err = vertex_error(
|
||||
429,
|
||||
"RESOURCE_EXHAUSTED",
|
||||
Some(vec![serde_json::json!({
|
||||
"@type": "type.googleapis.com/google.rpc.RetryInfo",
|
||||
"retryDelay": "15s"
|
||||
})]),
|
||||
});
|
||||
);
|
||||
assert_eq!(err.retry_delay(), Some(Duration::from_secs(15)));
|
||||
|
||||
assert_eq!(Error::NoCandidatesError.retry_delay(), None);
|
||||
|
||||
Reference in New Issue
Block a user