Skip to content

Commit 9639769

Browse files
committed
Add pre-initialize autovacuum integration test
1 parent 65b302f commit 9639769

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

tests/integration/common.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ impl TempDatabase {
8787
}
8888
}
8989

90+
pub fn new_with_autovacuum_full(sql: &str) -> Self {
91+
let mut path = TempDir::new().unwrap().keep();
92+
path.push("test.db");
93+
{
94+
let connection = rusqlite::Connection::open(&path).unwrap();
95+
connection.pragma_update(None, "page_size", 4096).unwrap();
96+
connection.pragma_update(None, "auto_vacuum", 1).unwrap();
97+
connection.execute_batch("VACUUM;").unwrap();
98+
connection.execute_batch(sql).unwrap();
99+
}
100+
let io: Arc<dyn turso_core::IO> = Arc::new(turso_core::PlatformIO::new().unwrap());
101+
let db = Database::open_file_with_flags(
102+
io.clone(),
103+
path.to_str().unwrap(),
104+
turso_core::OpenFlags::default(),
105+
turso_core::DatabaseOpts::new()
106+
.with_indexes(true)
107+
.with_index_method(true),
108+
None,
109+
)
110+
.unwrap();
111+
112+
Self { path, io, db }
113+
}
114+
90115
pub fn new_with_rusqlite(table_sql: &str) -> Self {
91116
let mut path = TempDir::new().unwrap().keep();
92117
path.push("test.db");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use core_tester::common::{self, maybe_setup_tracing, rusqlite_integrity_check, TempDatabase};
2+
use turso_core::Row;
3+
4+
#[test]
5+
6+
fn test_autovacuum_pointer_map_integrity() -> anyhow::Result<()> {
7+
let _ = env_logger::try_init();
8+
maybe_setup_tracing();
9+
10+
let tmp_db = TempDatabase::new_with_autovacuum_full(
11+
"CREATE TABLE seed_table(id INTEGER PRIMARY KEY, value TEXT);\
12+
INSERT INTO seed_table VALUES (1, 'seed');",
13+
);
14+
let conn = tmp_db.connect_limbo();
15+
16+
common::run_query(&tmp_db, &conn, "CREATE TABLE third(a);")?;
17+
for i in 1..=2000 {
18+
common::run_query(&tmp_db, &conn, &format!("INSERT INTO third VALUES ({i});"))?;
19+
}
20+
21+
common::run_query_on_row(&tmp_db, &conn, "PRAGMA integrity_check;", |row: &Row| {
22+
let res = row.get::<String>(0).unwrap();
23+
assert_eq!(res, "ok");
24+
})?;
25+
26+
rusqlite_integrity_check(tmp_db.path.as_path())?;
27+
28+
Ok(())
29+
}

tests/integration/storage/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
mod auto_vacuum;
12
#[cfg(feature = "checksum")]
23
mod checksum;

0 commit comments

Comments
 (0)