Skip to content

Commit ed2591a

Browse files
author
Dai Dao
authored
ISSUE-1111 add tests for search stream retry policy (#1128)
* add tests for search stream retry policy
1 parent 41fb388 commit ed2591a

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

quickwit-search/src/retry/search_stream.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ impl
7272

7373
#[cfg(test)]
7474
mod tests {
75-
use quickwit_proto::{LeafSearchStreamRequest, LeafSearchStreamResponse};
75+
use quickwit_proto::{
76+
LeafSearchStreamRequest, LeafSearchStreamResponse, SplitIdAndFooterOffsets,
77+
};
7678
use tokio::sync::mpsc::error::SendError;
7779

78-
use crate::retry::search_stream::LeafSearchStreamRetryPolicy;
80+
use crate::retry::search_stream::{LeafSearchStreamRetryPolicy, SuccessfullSplitIds};
7981
use crate::retry::RetryPolicy;
8082

8183
#[tokio::test]
@@ -90,4 +92,48 @@ mod tests {
9092
);
9193
assert!(retry_req_opt.is_none());
9294
}
95+
96+
#[tokio::test]
97+
async fn test_retry_policy_search_stream_should_not_retry_on_successful_response() {
98+
let retry_policy = LeafSearchStreamRetryPolicy {};
99+
let leaf_search_stream_req = LeafSearchStreamRequest::default();
100+
let successful_split_ids: Vec<String> = Vec::new();
101+
let retry_req_opt = retry_policy.retry_request(
102+
leaf_search_stream_req,
103+
Ok(SuccessfullSplitIds(successful_split_ids)).as_ref(),
104+
);
105+
assert!(retry_req_opt.is_none());
106+
}
107+
108+
#[tokio::test]
109+
async fn test_retry_policy_search_stream_should_retry_on_failed_splits() {
110+
let splits = vec![
111+
SplitIdAndFooterOffsets {
112+
split_id: "split_1".to_string(),
113+
split_footer_end: 100,
114+
split_footer_start: 0,
115+
},
116+
SplitIdAndFooterOffsets {
117+
split_id: "split_2".to_string(),
118+
split_footer_end: 100,
119+
split_footer_start: 0,
120+
},
121+
];
122+
123+
let retry_policy = LeafSearchStreamRetryPolicy {};
124+
let mut leaf_search_stream_req = LeafSearchStreamRequest::default();
125+
leaf_search_stream_req.split_offsets.push(splits[0].clone());
126+
leaf_search_stream_req.split_offsets.push(splits[1].clone());
127+
let successful_split_ids: Vec<String> = vec![splits[0].split_id.clone()];
128+
let retry_req_opt = retry_policy.retry_request(
129+
leaf_search_stream_req,
130+
Ok(SuccessfullSplitIds(successful_split_ids)).as_ref(),
131+
);
132+
assert!(retry_req_opt.is_some());
133+
assert_eq!(retry_req_opt.as_ref().unwrap().split_offsets.len(), 1);
134+
assert_eq!(
135+
&retry_req_opt.as_ref().unwrap().split_offsets[0].split_id,
136+
"split_2"
137+
);
138+
}
93139
}

0 commit comments

Comments
 (0)