use anyhow::Result;
use std::time::Duration;
use uni_db::Uni;
#[tokio::test]
async fn test_query_timeout() -> Result<()> {
let db = Uni::in_memory().build().await?;
db.schema().label("Node").apply().await?;
let tx = db.session().tx().await?;
for _ in 0..100 {
tx.execute("CREATE (:Node)").await?;
}
tx.commit().await?;
let res = db
.session()
.query_with("MATCH (n:Node) RETURN n")
.timeout(Duration::from_nanos(1))
.fetch_all()
.await;
assert!(res.is_err());
let err_msg = res.err().unwrap().to_string();
assert!(err_msg.contains("Query timed out"));
Ok(())
}
#[tokio::test]
async fn test_query_memory_limit() -> Result<()> {
let db = Uni::in_memory().build().await?;
db.schema().label("Node").apply().await?;
let tx = db.session().tx().await?;
for _ in 0..100 {
tx.execute("CREATE (:Node)").await?;
}
tx.commit().await?;
let res = db
.session()
.query_with("MATCH (n:Node) RETURN n")
.max_memory(100) .fetch_all()
.await;
assert!(res.is_err());
let err_msg = res.err().unwrap().to_string();
assert!(err_msg.contains("Query exceeded memory limit"));
Ok(())
}