Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace hardcoded temp directory paths #974

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ workspace-hack = { version = "0.1", path = "../../workspace-hack" }

[dev-dependencies]
test-macros = { path = "../test-macros" }
tempfile = "3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line at the end.

56 changes: 29 additions & 27 deletions crates/engine/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ impl SnapshotApi for Snapshot {
mod test {
use std::iter::{repeat, zip};

use tempfile::TempDir;

use clippy_utilities::NumericCast;
use test_macros::abort_on_panic;

Expand All @@ -342,8 +344,8 @@ mod test {

#[test]
fn write_batch_into_a_non_existing_table_should_fail() {
let dir = PathBuf::from("/tmp/write_batch_into_a_non_existing_table_should_fail");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("write_batch_into_a_non_existing_table_should_fail-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand All @@ -363,13 +365,13 @@ mod test {
let delete_range = WriteOperation::new_delete_range("hello", b"hello", b"world");
assert!(engine.write_multi(vec![delete_range], false).is_err());
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[test]
fn write_batch_should_success() {
let dir = PathBuf::from("/tmp/write_batch_should_success");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("write_batch_should_success-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand Down Expand Up @@ -409,13 +411,13 @@ mod test {
assert!(engine.get("kv", &get_key_1).unwrap().is_some());
assert!(engine.get("kv", &get_key_2).unwrap().is_none());
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[test]
fn get_operation_should_success() {
let dir = PathBuf::from("/tmp/get_operation_should_success");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("get_operation_should_success-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand Down Expand Up @@ -447,17 +449,17 @@ mod test {
.collect::<Vec<(Vec<u8>, Vec<u8>)>>();
assert_eq!(res_3.sort(), expected_all_values.sort());
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[tokio::test]
#[abort_on_panic]
async fn snapshot_should_work() {
let dir = PathBuf::from("/tmp/snapshot_should_work");
let origin_data_dir = dir.join("origin");
let recover_data_dir = dir.join("recover");
let snapshot_dir = dir.join("snapshot");
let snapshot_bak_dir = dir.join("snapshot_bak");
let dir = TempDir::with_prefix("snapshot_should_work-").unwrap();
let origin_data_dir = dir.path().join("origin");
let recover_data_dir = dir.path().join("recover");
let snapshot_dir = dir.path().join("snapshot");
let snapshot_bak_dir = dir.path().join("snapshot_bak");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(origin_data_dir), &TESTTABLES).unwrap(),
Expand Down Expand Up @@ -508,14 +510,14 @@ mod test {
assert!(value2.is_none());
}

std::fs::remove_dir_all(&dir).unwrap();
dir.close().unwrap();
}

#[tokio::test]
#[abort_on_panic]
async fn txn_write_multi_should_success() {
let dir = PathBuf::from("/tmp/txn_write_multi_should_success");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("txn_write_multi_should_success-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand Down Expand Up @@ -558,14 +560,14 @@ mod test {

txn.commit().unwrap();
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[tokio::test]
#[abort_on_panic]
async fn txn_get_operation_should_success() {
let dir = PathBuf::from("/tmp/txn_get_operation_should_success");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("txn_get_operation_should_success-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand All @@ -592,14 +594,14 @@ mod test {
assert_eq!(res_2, expected_multi_values);
txn.commit().unwrap();
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[tokio::test]
#[abort_on_panic]
async fn txn_operation_is_atomic() {
let dir = PathBuf::from("/tmp/txn_operation_should_be_atomic");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("txn_operation_should_be_atomic-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand All @@ -625,14 +627,14 @@ mod test {
assert_eq!(engine.get("kv", key).unwrap().unwrap(), val);
}
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[tokio::test]
#[abort_on_panic]
async fn txn_revert_should_success() {
let dir = PathBuf::from("/tmp/txn_revert_should_success");
let rocks_engine_path = dir.join("rocks_engine");
let dir = TempDir::with_prefix("txn_revert_should_success-").unwrap();
let rocks_engine_path = dir.path().join("rocks_engine");
let engines = vec![
Engine::new(EngineType::Memory, &TESTTABLES).unwrap(),
Engine::new(EngineType::Rocks(rocks_engine_path), &TESTTABLES).unwrap(),
Expand All @@ -659,6 +661,6 @@ mod test {
assert!(engine.get("kv", key).unwrap().is_none());
}
}
std::fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}
}
9 changes: 5 additions & 4 deletions crates/engine/src/rocksdb_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ impl SnapshotApi for RocksSnapshot {
#[cfg(test)]
mod test {
use std::env::temp_dir;
use tempfile::TempDir;

use test_macros::abort_on_panic;

Expand All @@ -735,9 +736,9 @@ mod test {
#[tokio::test]
#[abort_on_panic]
async fn test_rocks_errors() {
let dir = PathBuf::from("/tmp/test_rocks_errors");
let engine_path = dir.join("engine");
let snapshot_path = dir.join("snapshot");
let dir = TempDir::with_prefix("test_rocks_errors-").unwrap();
let engine_path = dir.path().join("engine");
let snapshot_path = dir.path().join("snapshot");
let engine = RocksEngine::new(engine_path, &TEST_TABLES).unwrap();
let res = engine.get("not_exist", "key");
assert!(res.is_err());
Expand All @@ -756,7 +757,7 @@ mod test {
};
let res = engine.apply_snapshot(fake_snapshot, &["not_exist"]).await;
assert!(res.is_err());
fs::remove_dir_all(dir).unwrap();
dir.close().unwrap();
}

#[test]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test_engine_size test also needs to be updated for consistency.

Expand Down
Loading