Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): add test for transaction isolation level on mssql #5054

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions quaint/src/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ async fn transactions_with_isolation_works(api: &mut dyn TestApi) -> crate::Resu
Ok(())
}

#[test_each_connector(tags("mssql"))]
async fn mssql_transaction_isolation_level(api: &mut dyn TestApi) -> crate::Result<()> {
// For Mssql, the isolation level is set on the connection and lives until it's changed.
// We need to test that the isolation level set per transaction is ignored.
let table = api.create_temp_table("id int, value int").await?;

// The connection default is "READ COMMITTED"
let conn = api.conn();

// Start a transaction with the default isolation level of "READ COMMITTED"
// and insert a row, but do not commit the transaction
let tx_a = conn.start_transaction(None).await?;
let insert = Insert::single_into(&table).value("value", 3).value("id", 4);
let rows_affected = tx_a.execute(insert.into()).await?;
assert_eq!(1, rows_affected);

// Start a transaction with an explicit isolation level of "READ UNCOMMITTED", which would ordinarily allow you to read
// rows that have been added but not committed.
let tx_b = conn.start_transaction(Some(IsolationLevel::ReadUncommitted)).await?;
let res = tx_b.query(Select::from_table(&table).into()).await?;

// The query should return an empty result set because the isolation level is set on the connection
assert_eq!(0, res.len());
Ok(())
}

// SQLite only supports serializable.
#[test_each_connector(tags("sqlite"))]
async fn sqlite_serializable_tx(api: &mut dyn TestApi) -> crate::Result<()> {
Expand Down
Loading