Skip to content

Commit

Permalink
Add normal high concurrency test
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Nov 4, 2024
1 parent 146387d commit 0d1ec1c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ mod interactive_tx {

#[test_suite(schema(generic), exclude(Sqlite("cfd1")))]
mod itx_isolation {
use std::sync::Arc;

use query_engine_tests::*;
use tokio::task::JoinSet;

// All (SQL) connectors support serializable.
#[connector_test(exclude(MongoDb, Sqlite("cfd1")))]
Expand Down Expand Up @@ -653,4 +656,45 @@ mod itx_isolation {

Ok(())
}

#[connector_test(exclude(Sqlite))]
async fn high_concurrency(runner: Runner) -> TestResult<()> {
let runner = Arc::new(runner);
let mut set = JoinSet::<TestResult<()>>::new();

for i in 1..=20 {
set.spawn({
let runner = Arc::clone(&runner);
async move {
let tx_id = runner.start_tx(5000, 5000, None).await?;

runner
.query_in_tx(
&tx_id,
format!(
r#"mutation {{
createOneTestModel(
data: {{
id: {i}
}}
) {{ id }}
}}"#
),
)
.await?
.assert_success();

runner.commit_tx(tx_id).await?.expect("commit must succeed");

Ok(())
}
});
}

while let Some(handle) = set.join_next().await {
handle.expect("task panicked or canceled")?;
}

Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ use query_engine_tests::*;
/// the database side and failures to start new transactions.
/// TODO: investigate the problem in pg and neon JS driver adapters, looks like some error is not
/// being handled properly in them.
///
/// For an example of an equivalent test that passes on all databases where the transactions don't
/// conflict and don't cause issues on the database side, see the `high_concurrency` test in the
/// `new::interactive_tx::interactive_tx` test suite.
#[test_suite(
schema(user),
exclude(Sqlite, MySql(8), SqlServer, Postgres("pg.js"), Postgres("neon.js"))
Expand Down

0 comments on commit 0d1ec1c

Please sign in to comment.