mirror of
https://github.com/atuinsh/atuin.git
synced 2025-08-09 07:15:12 +02:00
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.
This commit is contained in:
@ -762,6 +762,8 @@ impl Database for Sqlite {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::settings::test_local_timeout;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
@ -834,7 +836,9 @@ mod test {
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_search_prefix() {
|
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();
|
new_history_item(&mut db, "ls /home/ellie").await.unwrap();
|
||||||
|
|
||||||
assert_search_eq(&db, SearchMode::Prefix, FilterMode::Global, "ls", 1)
|
assert_search_eq(&db, SearchMode::Prefix, FilterMode::Global, "ls", 1)
|
||||||
@ -850,7 +854,9 @@ mod test {
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_search_fulltext() {
|
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();
|
new_history_item(&mut db, "ls /home/ellie").await.unwrap();
|
||||||
|
|
||||||
assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "ls", 1)
|
assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "ls", 1)
|
||||||
@ -934,7 +940,9 @@ mod test {
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_search_fuzzy() {
|
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/ellie").await.unwrap();
|
||||||
new_history_item(&mut db, "ls /home/frank").await.unwrap();
|
new_history_item(&mut db, "ls /home/frank").await.unwrap();
|
||||||
new_history_item(&mut db, "cd /home/Ellie").await.unwrap();
|
new_history_item(&mut db, "cd /home/Ellie").await.unwrap();
|
||||||
@ -1035,7 +1043,9 @@ mod test {
|
|||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn test_search_reordered_fuzzy() {
|
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.
|
// test ordering of results: we should choose the first, even though it happened longer ago.
|
||||||
|
|
||||||
new_history_item(&mut db, "curl").await.unwrap();
|
new_history_item(&mut db, "curl").await.unwrap();
|
||||||
@ -1069,7 +1079,9 @@ mod test {
|
|||||||
git_root: None,
|
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 {
|
for _i in 1..10000 {
|
||||||
new_history_item(&mut db, "i am a duplicated command")
|
new_history_item(&mut db, "i am a duplicated command")
|
||||||
.await
|
.await
|
||||||
|
@ -367,7 +367,7 @@ pub(crate) fn test_sqlite_store_timeout() -> f64 {
|
|||||||
std::env::var("ATUIN_TEST_SQLITE_STORE_TIMEOUT")
|
std::env::var("ATUIN_TEST_SQLITE_STORE_TIMEOUT")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|x| x.parse().ok())
|
.and_then(|x| x.parse().ok())
|
||||||
.unwrap_or(0.1)
|
.unwrap_or(crate::settings::test_local_timeout())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -845,6 +845,16 @@ impl Default for Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn test_local_timeout() -> f64 {
|
||||||
|
std::env::var("ATUIN_TEST_LOCAL_TIMEOUT")
|
||||||
|
.ok()
|
||||||
|
.and_then(|x| x.parse().ok())
|
||||||
|
// this hardcoded value should be replaced by a simple way to get the
|
||||||
|
// default local_timeout of Settings if possible
|
||||||
|
.unwrap_or(2.0)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
Reference in New Issue
Block a user