use tempfile in test

This commit is contained in:
Jussi Saurio
2025-05-25 10:25:52 +03:00
parent 64ef3f1343
commit 6254246541
3 changed files with 9 additions and 16 deletions

5
Cargo.lock generated
View File

@@ -1721,6 +1721,7 @@ name = "limbo"
version = "0.0.20"
dependencies = [
"limbo_core",
"tempfile",
"thiserror 2.0.12",
"tokio",
]
@@ -3479,9 +3480,9 @@ checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a"
[[package]]
name = "tempfile"
version = "3.19.1"
version = "3.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf"
checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
dependencies = [
"fastrand",
"getrandom 0.3.2",

View File

@@ -14,4 +14,5 @@ limbo_core = { workspace = true, features = ["io_uring"] }
thiserror = "2.0.9"
[dev-dependencies]
tempfile = "3.20.0"
tokio = { version = "1.29.1", features = ["full"] }

View File

@@ -352,13 +352,12 @@ impl<'a> FromIterator<&'a limbo_core::Value> for Row {
#[cfg(test)]
mod tests {
use super::*;
use tempfile::NamedTempFile;
#[tokio::test]
async fn test_database_persistence() -> Result<()> {
let db_path = "test_persistence.db";
// Ensure a clean state by removing the database file if it exists from a previous run
let _ = std::fs::remove_file(db_path);
let _ = std::fs::remove_file(format!("{}-wal", db_path));
let temp_file = NamedTempFile::new().unwrap();
let db_path = temp_file.path().to_str().unwrap();
// First, create the database, a table, and insert some data
{
@@ -391,18 +390,13 @@ mod tests {
assert!(rows.next().await?.is_none(), "Expected no more rows");
// Clean up the database file
let _ = std::fs::remove_file(db_path);
let _ = std::fs::remove_file(format!("{}-wal", db_path));
Ok(())
}
#[tokio::test]
async fn test_database_persistence_many_frames() -> Result<()> {
let db_path = "test_persistence_many_frames.db";
// Ensure a clean state by removing the database file if it exists from a previous run
let _ = std::fs::remove_file(db_path);
let _ = std::fs::remove_file(format!("{}-wal", db_path));
let temp_file = NamedTempFile::new().unwrap();
let db_path = temp_file.path().to_str().unwrap();
const NUM_INSERTS: usize = 100;
const TARGET_STRING_LEN: usize = 1024; // 1KB
@@ -489,9 +483,6 @@ mod tests {
),
}
// Clean up the database file
let _ = std::fs::remove_file(db_path);
let _ = std::fs::remove_file(format!("{}-wal", db_path));
Ok(())
}
}