Skip to content

Commit 4e65236

Browse files
cloutiertylerCentril
authored andcommitted
Add tests to ensure transactionality of drop/create table
1 parent b6a9abb commit 4e65236

File tree

1 file changed

+38
-0
lines changed
  • crates/core/src/db/datastore/locking_tx_datastore

1 file changed

+38
-0
lines changed

crates/core/src/db/datastore/locking_tx_datastore/datastore.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,44 @@ mod tests {
28922892
Ok(())
28932893
}
28942894

2895+
#[test]
2896+
fn test_drop_table_is_transactional() -> ResultTest<()> {
2897+
let (datastore, mut tx, table_id) = setup_table()?;
2898+
2899+
// Insert a row and commit.
2900+
insert(&datastore, &mut tx, table_id, &random_row())?;
2901+
commit(&datastore, tx)?;
2902+
2903+
// Create a transaction and drop the table and roll back.
2904+
let mut tx = begin_mut_tx(&datastore);
2905+
assert!(datastore.drop_table_mut_tx(&mut tx, table_id).is_ok());
2906+
datastore.rollback_mut_tx(tx);
2907+
2908+
// Ensure the table still exists in the next transaction.
2909+
let tx = begin_mut_tx(&datastore);
2910+
assert!(
2911+
datastore.table_id_exists_mut_tx(&tx, &table_id),
2912+
"Table should still exist",
2913+
);
2914+
2915+
Ok(())
2916+
}
2917+
2918+
#[test]
2919+
fn test_create_table_is_transactional() -> ResultTest<()> {
2920+
// Create a table in a failed transaction.
2921+
let (datastore, tx, table_id) = setup_table()?;
2922+
datastore.rollback_mut_tx(tx);
2923+
2924+
// Nothing should have happened.
2925+
let tx = begin_mut_tx(&datastore);
2926+
assert!(
2927+
!datastore.table_id_exists_mut_tx(&tx, &table_id),
2928+
"Table should not exist"
2929+
);
2930+
Ok(())
2931+
}
2932+
28952933
// TODO: Add the following tests
28962934
// - Create index with unique constraint and immediately insert a row that violates the constraint before committing.
28972935
// - Create a tx that inserts 2000 rows with an auto_inc column

0 commit comments

Comments
 (0)