aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-dotfiles
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-dotfiles
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-dotfiles')
-rw-r--r--crates/atuin-dotfiles/src/store.rs12
-rw-r--r--crates/atuin-dotfiles/src/store/var.rs14
2 files changed, 10 insertions, 16 deletions
diff --git a/crates/atuin-dotfiles/src/store.rs b/crates/atuin-dotfiles/src/store.rs
index f1789e2b..b77fa370 100644
--- a/crates/atuin-dotfiles/src/store.rs
+++ b/crates/atuin-dotfiles/src/store.rs
@@ -298,11 +298,13 @@ impl AliasStore {
}
#[cfg(test)]
-pub(crate) fn test_sqlite_store_timeout() -> f64 {
- std::env::var("ATUIN_TEST_SQLITE_STORE_TIMEOUT")
+pub(crate) fn test_local_timeout() -> f64 {
+ std::env::var("ATUIN_TEST_LOCAL_TIMEOUT")
.ok()
.and_then(|x| x.parse().ok())
- .unwrap_or(0.1)
+ // 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)]
@@ -313,7 +315,7 @@ mod tests {
use crate::shell::Alias;
- use super::{test_sqlite_store_timeout, AliasRecord, AliasStore, CONFIG_SHELL_ALIAS_VERSION};
+ use super::{test_local_timeout, AliasRecord, AliasStore, CONFIG_SHELL_ALIAS_VERSION};
use crypto_secretbox::{KeyInit, XSalsa20Poly1305};
#[test]
@@ -335,7 +337,7 @@ mod tests {
#[tokio::test]
async fn build_aliases() {
- let store = SqliteStore::new(":memory:", test_sqlite_store_timeout())
+ let store = SqliteStore::new(":memory:", test_local_timeout())
.await
.unwrap();
let key: [u8; 32] = XSalsa20Poly1305::generate_key(&mut OsRng).into();
diff --git a/crates/atuin-dotfiles/src/store/var.rs b/crates/atuin-dotfiles/src/store/var.rs
index 2d366f7e..0873b4d5 100644
--- a/crates/atuin-dotfiles/src/store/var.rs
+++ b/crates/atuin-dotfiles/src/store/var.rs
@@ -287,22 +287,14 @@ impl VarStore {
}
#[cfg(test)]
-pub(crate) fn test_sqlite_store_timeout() -> f64 {
- std::env::var("ATUIN_TEST_SQLITE_STORE_TIMEOUT")
- .ok()
- .and_then(|x| x.parse().ok())
- .unwrap_or(0.1)
-}
-
-#[cfg(test)]
mod tests {
use rand::rngs::OsRng;
use atuin_client::record::sqlite_store::SqliteStore;
- use crate::shell::Var;
+ use crate::{shell::Var, store::test_local_timeout};
- use super::{test_sqlite_store_timeout, VarRecord, VarStore, DOTFILES_VAR_VERSION};
+ use super::{VarRecord, VarStore, DOTFILES_VAR_VERSION};
use crypto_secretbox::{KeyInit, XSalsa20Poly1305};
#[test]
@@ -327,7 +319,7 @@ mod tests {
#[tokio::test]
async fn build_vars() {
- let store = SqliteStore::new(":memory:", test_sqlite_store_timeout())
+ let store = SqliteStore::new(":memory:", test_local_timeout())
.await
.unwrap();
let key: [u8; 32] = XSalsa20Poly1305::generate_key(&mut OsRng).into();