Skip to content

Commit e370776

Browse files
committed
test leak condition around prepared statements getting cleaned up after schema change
1 parent 4437b03 commit e370776

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

core/rs/integration_check/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
2-
2+
extern crate alloc;
33
mod t;
4+
use alloc::ffi::CString;
45
pub use crsql_bundle;
56
use libc_print::std_name::println;
67

@@ -43,6 +44,14 @@ pub fn opendb() -> Result<CRConnection, ResultCode> {
4344
Ok(CRConnection { db: connection })
4445
}
4546

47+
pub fn opendb_file(f: &str) -> Result<CRConnection, ResultCode> {
48+
let f = CString::new(f)?;
49+
let connection = sqlite::open(f.as_ptr())?;
50+
// connection.enable_load_extension(true)?;
51+
// connection.load_extension("../../dbg/crsqlite", None)?;
52+
Ok(CRConnection { db: connection })
53+
}
54+
4655
pub struct CRConnection {
4756
pub db: ManagedConnection,
4857
}

core/rs/integration_check/src/t/tableinfo.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,41 @@ fn test_create_clock_table_from_table_info() {
325325
}
326326

327327
fn test_leak_condition() {
328-
// updating table infos prepares stements
328+
// updating schemas prepares stements
329329
// re-pulling table infos should finalize those statements
330-
// we do not use `Drop` given we cannot return error conditions from `Drop`
330+
let c1w = crate::opendb_file("test_leak_condition").expect("Opened DB");
331+
let c2w = crate::opendb_file("test_leak_condition").expect("Opened DB");
332+
333+
let c1 = &c1w.db;
334+
let c2 = &c2w.db;
335+
336+
c1.exec_safe(
337+
"DROP TABLE IF EXISTS foo;
338+
DROP TABLE IF EXISTS bar;
339+
VACUUM;",
340+
)
341+
.expect("reset db");
342+
343+
c1.exec_safe("CREATE TABLE foo (a not null, b not null, primary key (a, b));")
344+
.expect("made foo");
345+
c1.exec_safe("SELECT crsql_as_crr('foo')")
346+
.expect("made foo a crr");
347+
c1.exec_safe("INSERT INTO foo VALUES (1, 2)")
348+
.expect("inserted into foo");
349+
c1.exec_safe("UPDATE FOO set b = 3").expect("updated foo");
350+
c2.exec_safe("INSERT INTO foo VALUES (2, 3)")
351+
.expect("inserted into foo");
352+
c2.exec_safe("CREATE TABLE bar (a)").expect("created bar");
353+
c1.exec_safe("INSERT INTO foo VALUES (3, 4)")
354+
.expect("inserted into foo");
355+
c2.exec_safe("INSERT INTO foo VALUES (4, 5)")
356+
.expect("inserted into foo");
331357
}
332358

333359
pub fn run_suite() {
334360
test_ensure_table_infos_are_up_to_date();
335361
test_pull_table_info();
336362
test_is_table_compatible();
337363
test_create_clock_table_from_table_info();
364+
test_leak_condition();
338365
}

py/perf/perf.ipynb

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)