speed up query timeout test
This commit is contained in:
1 parent
ed475f1d1b
commit
33705b9cbb
1 file changed
+15
-4
@@ -90,6 +90,17 @@ async fn wait_for_query<F>(
|
|||||||
cancel_token: Option<CancellationToken>,
|
cancel_token: Option<CancellationToken>,
|
||||||
future: F,
|
future: F,
|
||||||
) -> Result<db::QueryResult, String>
|
) -> Result<db::QueryResult, String>
|
||||||
|
where
|
||||||
|
F: Future<Output = Result<db::QueryResult, String>>,
|
||||||
|
{
|
||||||
|
wait_for_query_with_timeout(cancel_token, QUERY_TIMEOUT, future).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn wait_for_query_with_timeout<F>(
|
||||||
|
cancel_token: Option<CancellationToken>,
|
||||||
|
timeout_duration: Duration,
|
||||||
|
future: F,
|
||||||
|
) -> Result<db::QueryResult, String>
|
||||||
where
|
where
|
||||||
F: Future<Output = Result<db::QueryResult, String>>,
|
F: Future<Output = Result<db::QueryResult, String>>,
|
||||||
{
|
{
|
||||||
@@ -97,10 +108,10 @@ where
|
|||||||
tokio::select! {
|
tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
_ = token.cancelled() => Err(canceled_error()),
|
_ = token.cancelled() => Err(canceled_error()),
|
||||||
result = timeout(QUERY_TIMEOUT, future) => result.map_err(|_| timeout_error())?,
|
result = timeout(timeout_duration, future) => result.map_err(|_| timeout_error())?,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
timeout(QUERY_TIMEOUT, future)
|
timeout(timeout_duration, future)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| timeout_error())?
|
.map_err(|_| timeout_error())?
|
||||||
}
|
}
|
||||||
@@ -326,8 +337,8 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn wait_for_query_without_token_still_times_out() {
|
async fn wait_for_query_without_token_still_times_out() {
|
||||||
let result = wait_for_query(None, async {
|
let result = wait_for_query_with_timeout(None, Duration::from_millis(10), async {
|
||||||
tokio::time::sleep(Duration::from_secs(31)).await;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
Ok(db::QueryResult {
|
Ok(db::QueryResult {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
rows: vec![],
|
rows: vec![],
|
||||||
|
|||||||
Reference in new issue
Block a user