aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src/database.rs
diff options
context:
space:
mode:
authorJax Young <jaxvanyang@gmail.com>2024-08-05 21:22:40 +0800
committerGitHub <noreply@github.com>2024-08-05 14:22:40 +0100
commit90e7d28173ae281ba8c4e396c98da9b093b3bb42 (patch)
tree141d62fa269dd72b9e4633794cb182e11db739bd /crates/atuin-client/src/database.rs
parentfix(theme): Restore original colours (#2339) (diff)
downloadatuin-90e7d28173ae281ba8c4e396c98da9b093b3bb42.zip
test: add env ATUIN_TEST_LOCAL_TIMEOUT to control test timeout of SQLite (#2337)
* test: add env ATUIN_TEST_LOCAL_TIMEOUT to control test timeout of SQLite This make it possible to control the timeout of SQLite operations in test. And ATUIN_TEST_LOCAL_TIMEOUT defaults to the default local_timeout, which is actually used in the client. Instead of a small timeout (0.1), this change makes the test less likely to fail and better imitate the default behavior. SQLite operation timeout was first introduced from #1590, including connection and store timeout. The env ATUIN_TEST_SQLITE_STORE_TIMEOUT which added by #1703 only specify the store timeout. This commit doesn't deprecate ATUIN_TEST_SQLITE_STORE_TIMEOUT, but control it by setting its default to the new env ATUIN_TEST_LOCAL_TIMEOUT. * test!: replace ATUIN_TEST_SQLITE_STORE_TIMEOUT with ATUIN_TEST_LOCAL_TIMEOUT This deprecate ATUIN_TEST_SQLITE_STORE_TIMEOUT for simplicity as the new env ATUIN_TEST_LOCAL_TIMEOUT can control both connection and store timeout of SQLite in test. Details see 4d88611. Revert: #1703.
Diffstat (limited to 'crates/atuin-client/src/database.rs')
-rw-r--r--crates/atuin-client/src/database.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/crates/atuin-client/src/database.rs b/crates/atuin-client/src/database.rs
index d01dadb4..4f126030 100644
--- a/crates/atuin-client/src/database.rs
+++ b/crates/atuin-client/src/database.rs
@@ -762,6 +762,8 @@ impl Database for Sqlite {
#[cfg(test)]
mod test {
+ use crate::settings::test_local_timeout;
+
use super::*;
use std::time::{Duration, Instant};
@@ -834,7 +836,9 @@ mod test {
#[tokio::test(flavor = "multi_thread")]
async fn test_search_prefix() {
- let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap();
+ let mut db = Sqlite::new("sqlite::memory:", test_local_timeout())
+ .await
+ .unwrap();
new_history_item(&mut db, "ls /home/ellie").await.unwrap();
assert_search_eq(&db, SearchMode::Prefix, FilterMode::Global, "ls", 1)
@@ -850,7 +854,9 @@ mod test {
#[tokio::test(flavor = "multi_thread")]
async fn test_search_fulltext() {
- let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap();
+ let mut db = Sqlite::new("sqlite::memory:", test_local_timeout())
+ .await
+ .unwrap();
new_history_item(&mut db, "ls /home/ellie").await.unwrap();
assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "ls", 1)
@@ -934,7 +940,9 @@ mod test {
#[tokio::test(flavor = "multi_thread")]
async fn test_search_fuzzy() {
- let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap();
+ let mut db = Sqlite::new("sqlite::memory:", test_local_timeout())
+ .await
+ .unwrap();
new_history_item(&mut db, "ls /home/ellie").await.unwrap();
new_history_item(&mut db, "ls /home/frank").await.unwrap();
new_history_item(&mut db, "cd /home/Ellie").await.unwrap();
@@ -1035,7 +1043,9 @@ mod test {
#[tokio::test(flavor = "multi_thread")]
async fn test_search_reordered_fuzzy() {
- let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap();
+ let mut db = Sqlite::new("sqlite::memory:", test_local_timeout())
+ .await
+ .unwrap();
// test ordering of results: we should choose the first, even though it happened longer ago.
new_history_item(&mut db, "curl").await.unwrap();
@@ -1069,7 +1079,9 @@ mod test {
git_root: None,
};
- let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap();
+ let mut db = Sqlite::new("sqlite::memory:", test_local_timeout())
+ .await
+ .unwrap();
for _i in 1..10000 {
new_history_item(&mut db, "i am a duplicated command")
.await