Skip to content

Commit

Permalink
[refactor] Using Timeout when sending request message
Browse files Browse the repository at this point in the history
Signed-off-by: dd di cesare <[email protected]>
  • Loading branch information
didierofrivia committed Oct 4, 2024
1 parent f490dd4 commit 9f9aefd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/operation_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ impl Operation {
fn trigger(&self) -> Result<u32, Status> {
if let Some(message) = (self.grpc_message_build_fn)(self.get_extension_type(), &self.action)
{
let res = self
.service
.send(self.get_map_values_bytes_fn, self.grpc_call_fn, message);
let res = self.service.send(
self.get_map_values_bytes_fn,
self.grpc_call_fn,
message,
self.extension.timeout.0,
);
self.set_result(res);
self.next_state();
res
Expand Down Expand Up @@ -233,6 +236,7 @@ fn grpc_message_build_fn(
#[cfg(test)]
mod tests {
use super::*;
use crate::configuration::Timeout;
use crate::envoy::RateLimitRequest;
use protobuf::RepeatedField;
use std::time::Duration;
Expand Down Expand Up @@ -287,6 +291,7 @@ mod tests {
extension_type,
endpoint: "local".to_string(),
failure_mode: FailureMode::Deny,
timeout: Timeout(Duration::from_millis(42)),
}),
action: Action {
extension: "local".to_string(),
Expand Down
3 changes: 2 additions & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl GrpcServiceHandler {
get_map_values_bytes_fn: GetMapValuesBytesFn,
grpc_call_fn: GrpcCallFn,
message: GrpcMessageRequest,
timeout: Duration,
) -> Result<u32, Status> {
let msg = Message::write_to_bytes(&message).unwrap();
let metadata = self
Expand All @@ -99,7 +100,7 @@ impl GrpcServiceHandler {
self.service.method(),
metadata,
Some(&msg),
Duration::from_secs(5),
timeout,
)
}

Expand Down
12 changes: 8 additions & 4 deletions tests/rate_limited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ fn it_limits() {
"limitador": {
"type": "ratelimit",
"endpoint": "limitador-cluster",
"failureMode": "deny"
"failureMode": "deny",
"timeout": "5s"
}
},
"policies": [
Expand Down Expand Up @@ -249,7 +250,8 @@ fn it_passes_additional_headers() {
"limitador": {
"type": "ratelimit",
"endpoint": "limitador-cluster",
"failureMode": "deny"
"failureMode": "deny",
"timeout": "5s"
}
},
"policies": [
Expand Down Expand Up @@ -418,7 +420,8 @@ fn it_rate_limits_with_empty_conditions() {
"limitador": {
"type": "ratelimit",
"endpoint": "limitador-cluster",
"failureMode": "deny"
"failureMode": "deny",
"timeout": "5s"
}
},
"policies": [
Expand Down Expand Up @@ -536,7 +539,8 @@ fn it_does_not_rate_limits_when_selector_does_not_exist_and_misses_default_value
"limitador": {
"type": "ratelimit",
"endpoint": "limitador-cluster",
"failureMode": "deny"
"failureMode": "deny",
"timeout": "5s"
}
},
"policies": [
Expand Down

0 comments on commit 9f9aefd

Please sign in to comment.