Skip to content

Commit c86414f

Browse files
committed
..
1 parent 8988277 commit c86414f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/executor/src/executors/timeout.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl SubgraphExecutor for TimeoutExecutor {
169169
#[cfg(test)]
170170
mod tests {
171171
use async_trait::async_trait;
172+
use hive_router_config::parse_yaml_config;
172173
use http::Method;
173174
use ntex_http::HeaderMap;
174175

@@ -258,4 +259,36 @@ mod tests {
258259
"Expected 10000ms for mutation"
259260
);
260261
}
262+
263+
#[test]
264+
fn get_timeout_duration_from_fixed_duration() {
265+
let yaml_str = r#"
266+
traffic_shaping:
267+
all:
268+
timeout:
269+
duration: 7s
270+
"#;
271+
let config = parse_yaml_config(yaml_str.to_string()).unwrap();
272+
let mock_executor = MockExecutor {}.to_boxed_arc();
273+
let timeout_executor = TimeoutExecutor::try_new(
274+
"http://example.com/graphql".parse().unwrap(),
275+
&config.traffic_shaping.all.timeout.unwrap(),
276+
mock_executor,
277+
)
278+
.unwrap();
279+
280+
let headers = HeaderMap::new();
281+
let client_request = ClientRequestDetails {
282+
operation: OperationDetails {
283+
name: Some("TestQuery".to_string()),
284+
kind: "query",
285+
query: "query TestQuery { field }".into(),
286+
},
287+
url: "http://example.com/graphql".parse().unwrap(),
288+
headers: &headers,
289+
method: Method::POST,
290+
};
291+
let duration = timeout_executor.get_timeout_duration(&client_request);
292+
assert_eq!(duration, Some(std::time::Duration::from_millis(7000)));
293+
}
261294
}

lib/router-config/src/traffic_shaping.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ pub struct TrafficShapingExecutorConfig {
4646
#[serde(rename_all = "camelCase")]
4747
pub enum SubgraphTimeoutConfig {
4848
Expression(String),
49+
#[serde(deserialize_with = "humantime_serde")]
4950
Duration(Duration),
5051
}
5152

53+
fn humantime_serde<'de, D>(deserializer: D) -> Result<Duration, D::Error>
54+
where
55+
D: serde::Deserializer<'de>,
56+
{
57+
humantime_serde::deserialize(deserializer)
58+
}
59+
5260
impl Default for TrafficShapingExecutorConfig {
5361
fn default() -> Self {
5462
Self {

0 commit comments

Comments
 (0)