mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-19 06:55:18 +01:00
simple write multi threaded test
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::common::TempDatabase;
|
||||
|
||||
#[test]
|
||||
@@ -25,3 +27,39 @@ fn test_schema_change() {
|
||||
};
|
||||
println!("{:?} {:?}", row.get_value(0), row.get_value(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_multiple_connections() -> anyhow::Result<()> {
|
||||
let tries = 10;
|
||||
for _ in 0..tries {
|
||||
let tmp_db = Arc::new(TempDatabase::new_empty(false));
|
||||
{
|
||||
let conn = tmp_db.connect_limbo();
|
||||
conn.execute("CREATE TABLE t(x)").unwrap();
|
||||
}
|
||||
|
||||
let mut threads = Vec::new();
|
||||
for i in 0..10 {
|
||||
let tmp_db_ = tmp_db.clone();
|
||||
threads.push(std::thread::spawn(move || {
|
||||
let conn = tmp_db_.connect_limbo();
|
||||
conn.execute(format!("INSERT INTO t VALUES ({i})").as_str())
|
||||
.unwrap();
|
||||
}));
|
||||
}
|
||||
for thread in threads {
|
||||
thread.join().unwrap();
|
||||
}
|
||||
|
||||
let conn = tmp_db.connect_limbo();
|
||||
let mut stmt = conn.prepare("SELECT * FROM t").unwrap();
|
||||
let mut rows = Vec::new();
|
||||
while matches!(stmt.step().unwrap(), turso_core::StepResult::Row) {
|
||||
let row = stmt.row().unwrap();
|
||||
rows.push(row.get::<i64>(0).unwrap());
|
||||
}
|
||||
rows.sort();
|
||||
assert_eq!(rows, (0..10).collect::<Vec<_>>());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user