Skip to content

Commit

Permalink
test leak condition around prepared statements getting cleaned up aft…
Browse files Browse the repository at this point in the history
…er schema change
  • Loading branch information
tantaman committed Sep 29, 2023
1 parent 032c2cc commit 10932f6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
11 changes: 10 additions & 1 deletion core/rs/integration_check/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![no_std]

extern crate alloc;
mod t;
use alloc::ffi::CString;
pub use crsql_bundle;
use libc_print::std_name::println;

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

pub fn opendb_file(f: &str) -> Result<CRConnection, ResultCode> {
let f = CString::new(f)?;
let connection = sqlite::open(f.as_ptr())?;
// connection.enable_load_extension(true)?;
// connection.load_extension("../../dbg/crsqlite", None)?;
Ok(CRConnection { db: connection })
}

pub struct CRConnection {
pub db: ManagedConnection,
}
Expand Down
31 changes: 29 additions & 2 deletions core/rs/integration_check/src/t/tableinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,41 @@ fn test_create_clock_table_from_table_info() {
}

fn test_leak_condition() {
// updating table infos prepares stements
// updating schemas prepares stements
// re-pulling table infos should finalize those statements
// we do not use `Drop` given we cannot return error conditions from `Drop`
let c1w = crate::opendb_file("test_leak_condition").expect("Opened DB");
let c2w = crate::opendb_file("test_leak_condition").expect("Opened DB");

let c1 = &c1w.db;
let c2 = &c2w.db;

c1.exec_safe(
"DROP TABLE IF EXISTS foo;
DROP TABLE IF EXISTS bar;
VACUUM;",
)
.expect("reset db");

c1.exec_safe("CREATE TABLE foo (a not null, b not null, primary key (a, b));")
.expect("made foo");
c1.exec_safe("SELECT crsql_as_crr('foo')")
.expect("made foo a crr");
c1.exec_safe("INSERT INTO foo VALUES (1, 2)")
.expect("inserted into foo");
c1.exec_safe("UPDATE FOO set b = 3").expect("updated foo");
c2.exec_safe("INSERT INTO foo VALUES (2, 3)")
.expect("inserted into foo");
c2.exec_safe("CREATE TABLE bar (a)").expect("created bar");
c1.exec_safe("INSERT INTO foo VALUES (3, 4)")
.expect("inserted into foo");
c2.exec_safe("INSERT INTO foo VALUES (4, 5)")
.expect("inserted into foo");
}

pub fn run_suite() {
test_ensure_table_infos_are_up_to_date();
test_pull_table_info();
test_is_table_compatible();
test_create_clock_table_from_table_info();
test_leak_condition();
}
30 changes: 15 additions & 15 deletions py/perf/perf.ipynb

Large diffs are not rendered by default.

0 comments on commit 10932f6

Please sign in to comment.