Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

speed up query timeout test

SuLe33705b9cbbb1
diff --git a/src-tauri/src/commands/query.rs b/src-tauri/src/commands/query.rs
index 7ac0f99364..c406dce54b 100644
--- a/src-tauri/src/commands/query.rs
+++ b/src-tauri/src/commands/query.rs
@@ -90,6 +90,17 @@ async fn wait_for_query<F>(
cancel_token: Option<CancellationToken>,
future: F,
) -> 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
F: Future<Output = Result<db::QueryResult, String>>,
{
@@ -97,10 +108,10 @@ where
tokio::select! {
biased;
_ = 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 {
- timeout(QUERY_TIMEOUT, future)
+ timeout(timeout_duration, future)
.await
.map_err(|_| timeout_error())?
}
@@ -326,8 +337,8 @@ mod tests {
#[tokio::test]
async fn wait_for_query_without_token_still_times_out() {
- let result = wait_for_query(None, async {
- tokio::time::sleep(Duration::from_secs(31)).await;
+ let result = wait_for_query_with_timeout(None, Duration::from_millis(10), async {
+ tokio::time::sleep(Duration::from_secs(1)).await;
Ok(db::QueryResult {
columns: vec![],
rows: vec![],