diff options
author | Eric Long <i@hack3r.moe> | 2024-02-12 17:25:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-12 09:25:06 +0000 |
commit | 5a805dc22c99050db0a54f35e660516c57fa4b94 (patch) | |
tree | ef1479f47f6c0099e0094a73b9bf447541500627 /atuin-client/src/record | |
parent | 1464cb657a47e7b5705194302532f3ecf37c7649 (diff) |
feat: use ATUIN_TEST_SQLITE_STORE_TIMEOUT to specify test timeout of SQLite store (#1703)
Low-end devices like RISC-V SBCs are sometimes too slow to initialize SQLite in 0.1s. Option to specify a higher value allows check to pass on such devices with relaxed restrictions.
Diffstat (limited to 'atuin-client/src/record')
-rw-r--r-- | atuin-client/src/record/sqlite_store.rs | 52 | ||||
-rw-r--r-- | atuin-client/src/record/sync.rs | 6 |
2 files changed, 43 insertions, 15 deletions
diff --git a/atuin-client/src/record/sqlite_store.rs b/atuin-client/src/record/sqlite_store.rs index e5e3b9cd5..6333bb27a 100644 --- a/atuin-client/src/record/sqlite_store.rs +++ b/atuin-client/src/record/sqlite_store.rs @@ -352,6 +352,14 @@ impl Store for SqliteStore { } #[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 atuin_common::{ record::{DecryptedData, EncryptedData, Host, HostId, Record}, @@ -363,7 +371,7 @@ mod tests { record::{encryption::PASETO_V4, store::Store}, }; - use super::SqliteStore; + use super::{test_sqlite_store_timeout, SqliteStore}; fn test_record() -> Record<EncryptedData> { Record::builder() @@ -380,7 +388,7 @@ mod tests { #[tokio::test] async fn create_db() { - let db = SqliteStore::new(":memory:", 0.1).await; + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()).await; assert!( db.is_ok(), @@ -391,7 +399,9 @@ mod tests { #[tokio::test] async fn push_record() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let record = test_record(); db.push(&record).await.expect("failed to insert record"); @@ -399,7 +409,9 @@ mod tests { #[tokio::test] async fn get_record() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let record = test_record(); db.push(&record).await.unwrap(); @@ -410,7 +422,9 @@ mod tests { #[tokio::test] async fn last() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let record = test_record(); db.push(&record).await.unwrap(); @@ -428,7 +442,9 @@ mod tests { #[tokio::test] async fn first() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let record = test_record(); db.push(&record).await.unwrap(); @@ -446,7 +462,9 @@ mod tests { #[tokio::test] async fn len() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let record = test_record(); db.push(&record).await.unwrap(); @@ -460,7 +478,9 @@ mod tests { #[tokio::test] async fn len_tag() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let record = test_record(); db.push(&record).await.unwrap(); @@ -474,7 +494,9 @@ mod tests { #[tokio::test] async fn len_different_tags() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); // these have different tags, so the len should be the same // we model multiple stores within one database @@ -494,7 +516,9 @@ mod tests { #[tokio::test] async fn append_a_bunch() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let mut tail = test_record(); db.push(&tail).await.expect("failed to push record"); @@ -519,7 +543,9 @@ mod tests { #[tokio::test] async fn append_a_big_bunch() { - let db = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let db = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let mut records: Vec<Record<EncryptedData>> = Vec::with_capacity(10000); @@ -542,7 +568,9 @@ mod tests { #[tokio::test] async fn re_encrypt() { - let store = SqliteStore::new(":memory:", 0.1).await.unwrap(); + let store = SqliteStore::new(":memory:", test_sqlite_store_timeout()) + .await + .unwrap(); let (key, _) = generate_encoded_key().unwrap(); let data = vec![0u8, 1u8, 2u8, 3u8]; let host_id = HostId(uuid_v7()); diff --git a/atuin-client/src/record/sync.rs b/atuin-client/src/record/sync.rs index e3644371d..02c53d44a 100644 --- a/atuin-client/src/record/sync.rs +++ b/atuin-client/src/record/sync.rs @@ -324,7 +324,7 @@ mod tests { use crate::record::{ encryption::PASETO_V4, - sqlite_store::SqliteStore, + sqlite_store::{test_sqlite_store_timeout, SqliteStore}, store::Store, sync::{self, Operation}, }; @@ -351,10 +351,10 @@ mod tests { local_records: Vec<Record<EncryptedData>>, remote_records: Vec<Record<EncryptedData>>, ) -> (SqliteStore, Vec<Diff>) { - let local_store = SqliteStore::new(":memory:", 0.1) + let local_store = SqliteStore::new(":memory:", test_sqlite_store_timeout()) .await .expect("failed to open in memory sqlite"); - let remote_store = SqliteStore::new(":memory:", 0.1) + let remote_store = SqliteStore::new(":memory:", test_sqlite_store_timeout()) .await .expect("failed to open in memory sqlite"); // "remote" |