Skip to content

Commit

Permalink
feat: use in-memory SQLite DB to avoid conflicts across tests run in …
Browse files Browse the repository at this point in the history
…parallel
  • Loading branch information
bonsairobo committed Dec 3, 2024
1 parent 2705f20 commit ca0843b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/sqlite/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,21 +974,24 @@ async fn it_can_use_transaction_options() -> anyhow::Result<()> {
Ok(())
}

let mut conn = new::<Sqlite>().await?;
let mut conn = SqliteConnectOptions::new()
.in_memory(true)
.connect()
.await
.unwrap();

check_txn_state(&mut conn, SqliteTransactionState::None).await?;

let mut tx = conn.begin_with("BEGIN DEFERRED").await?;
check_txn_state(&mut *tx, SqliteTransactionState::None).await?;
check_txn_state(&mut tx, SqliteTransactionState::None).await?;
drop(tx);

let mut tx = conn.begin_with("BEGIN IMMEDIATE").await?;
check_txn_state(&mut *tx, SqliteTransactionState::Write).await?;
check_txn_state(&mut tx, SqliteTransactionState::Write).await?;
drop(tx);

// Note: may result in database locked errors if tests are run in parallel
let mut tx = conn.begin_with("BEGIN EXCLUSIVE").await?;
check_txn_state(&mut *tx, SqliteTransactionState::Write).await?;
check_txn_state(&mut tx, SqliteTransactionState::Write).await?;
drop(tx);

Ok(())
Expand Down

0 comments on commit ca0843b

Please sign in to comment.