Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7db658

Browse files
author
Philipp Korber
committed
Test partial rollback of nested commits.
Related to sfackler#371.
1 parent 12546ec commit a7db658

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

postgres/tests/test.rs

+35
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,41 @@ fn test_nested_transactions_finish() {
331331
);
332332
}
333333

334+
#[test]
335+
fn test_nested_transactions_partial_rollback() {
336+
let conn = or_panic!(Connection::connect(
337+
"postgres://postgres@localhost:5433",
338+
TlsMode::None,
339+
));
340+
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
341+
342+
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
343+
344+
{
345+
let trans = or_panic!(conn.transaction());
346+
or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32]));
347+
{
348+
let trans = or_panic!(trans.transaction());
349+
or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&3i32]));
350+
{
351+
let trans = or_panic!(trans.transaction());
352+
or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&4i32]));
353+
drop(trans);
354+
}
355+
drop(trans);
356+
}
357+
or_panic!(trans.commit());
358+
}
359+
360+
let stmt = or_panic!(conn.prepare("SELECT * FROM foo ORDER BY id"));
361+
let result = or_panic!(stmt.query(&[]));
362+
363+
assert_eq!(
364+
vec![1i32, 2],
365+
result.iter().map(|row| row.get(0)).collect::<Vec<i32>>()
366+
);
367+
}
368+
334369
#[test]
335370
#[should_panic(expected = "active transaction")]
336371
fn test_conn_trans_when_nested() {

0 commit comments

Comments
 (0)