use TempDatabase from commons in tests/

This commit is contained in:
Nikita Sivukhin 2025-02-02 19:34:15 +04:00
parent 43c9fc3c5c
commit 300f278ff3
5 changed files with 29 additions and 15 deletions

View file

@ -14,10 +14,6 @@ path = "lib.rs"
name = "integration_tests"
path = "integration/mod.rs"
[[test]]
name = "fuzz_tests"
path = "fuzz/mod.rs"
[dependencies]
anyhow = "1.0.75"
clap = { version = "4.5", features = ["derive"] }

View file

@ -12,6 +12,13 @@ pub struct TempDatabase {
#[allow(dead_code, clippy::arc_with_non_send_sync)]
impl TempDatabase {
pub fn new_empty() -> Self {
let mut path = TempDir::new().unwrap().into_path();
path.push("test.db");
let io: Arc<dyn limbo_core::IO> = Arc::new(limbo_core::PlatformIO::new().unwrap());
Self { path, io }
}
pub fn new(table_sql: &str) -> Self {
let mut path = TempDir::new().unwrap().into_path();
path.push("test.db");

View file

@ -2,14 +2,25 @@ pub mod grammar_generator;
#[cfg(test)]
mod tests {
use std::{rc::Rc, sync::Arc};
use std::rc::Rc;
use limbo_core::Database;
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
use rusqlite::params;
use crate::grammar_generator::{rand_int, GrammarGenerator};
use crate::{
common::TempDatabase,
fuzz::grammar_generator::{rand_int, GrammarGenerator},
};
fn rng_from_time() -> (ChaCha8Rng, u64) {
let seed = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();
let rng = ChaCha8Rng::seed_from_u64(seed);
(rng, seed)
}
fn sqlite_exec_row(conn: &rusqlite::Connection, query: &str) -> Vec<rusqlite::types::Value> {
let mut stmt = conn.prepare(&query).unwrap();
@ -56,9 +67,8 @@ mod tests {
#[test]
pub fn arithmetic_expression_fuzz_ex1() {
let io = Arc::new(limbo_core::PlatformIO::new().unwrap());
let limbo_db = Database::open_file(io, ":memory:").unwrap();
let limbo_conn = limbo_db.connect();
let db = TempDatabase::new_empty();
let limbo_conn = db.connect_limbo();
let sqlite_conn = rusqlite::Connection::open_in_memory().unwrap();
for query in [
@ -118,13 +128,13 @@ mod tests {
let sql = g.create().concat(" ").push_str("SELECT").push(expr).build();
let io = Arc::new(limbo_core::PlatformIO::new().unwrap());
let limbo_db = Database::open_file(io, ":memory:").unwrap();
let limbo_conn = limbo_db.connect();
let db = TempDatabase::new_empty();
let limbo_conn = db.connect_limbo();
let sqlite_conn = rusqlite::Connection::open_in_memory().unwrap();
let mut rng = ChaCha8Rng::seed_from_u64(0);
for _ in 0..16 * 1024 {
let (mut rng, seed) = rng_from_time();
println!("seed: {}", seed);
for _ in 0..1024 {
let query = g.generate(&mut rng, sql, 50);
let limbo = limbo_exec_row(&limbo_conn, &query);
let sqlite = sqlite_exec_row(&sqlite_conn, &query);

View file

@ -1,4 +1,5 @@
mod common;
mod functions;
mod fuzz;
mod pragma;
mod query_processing;