use storage_bindings::{LogLevel, StorageConfig, StorageNode};
use tempfile::tempdir;
#[tokio::test(flavor = "multi_thread")]
async fn test_no_memory_leak() {
for i in 0..10 {
let temp_dir = tempdir().unwrap();
let config = StorageConfig::new()
.log_level(LogLevel::Error)
.data_dir(temp_dir.path().join(format!("storage_{}", i)));
let node = StorageNode::new(config).await.unwrap();
node.start().await.unwrap();
node.stop().await.unwrap();
node.destroy().await.unwrap();
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_no_memory_leak_with_operations() {
for i in 0..5 {
let temp_dir = tempdir().unwrap();
let config = StorageConfig::new()
.log_level(LogLevel::Error)
.data_dir(temp_dir.path().join(format!("storage_{}", i)));
let node = StorageNode::new(config).await.unwrap();
node.start().await.unwrap();
let _version = node.version().await.unwrap();
let _peer_id = node.peer_id().await.unwrap();
let _repo = node.repo().await.unwrap();
node.stop().await.unwrap();
node.destroy().await.unwrap();
}
}
#[tokio::test(flavor = "multi_thread")]
async fn test_multiple_references_prevent_destroy() {
let temp_dir = tempdir().unwrap();
let config = StorageConfig::new()
.log_level(LogLevel::Error)
.data_dir(temp_dir.path().join("storage"));
let node = StorageNode::new(config).await.unwrap();
let node_clone = node.clone();
node.start().await.unwrap();
node.stop().await.unwrap();
let result = node.clone().destroy().await;
assert!(result.is_err());
drop(node_clone);
let result = node.destroy().await;
assert!(result.is_ok());
}