use cute_sqlite_kv::KVStore;
use std::sync::{Arc, Barrier};
#[test]
fn concurrent_cold_open_never_locks() {
let dir = tempfile::tempdir().unwrap();
let rounds = 50;
let threads = 16;
for r in 0..rounds {
let path = dir.path().join(format!("db_{r}.sqlite"));
let barrier = Arc::new(Barrier::new(threads));
let handles: Vec<_> = (0..threads)
.map(|_| {
let p = path.clone();
let b = barrier.clone();
std::thread::spawn(move || {
b.wait();
let store = KVStore::new_from_file(&p)
.map_err(|e| e.to_string())
.expect("concurrent cold open should not fail");
store.insert("k", "v");
})
})
.collect();
for h in handles {
h.join().unwrap();
}
}
}