-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
begin_test_transaction
flaky when ran in async context
#2733
Comments
I would call this expected behaviour. |
@weiznich thanks for clarifying and sharing the customization trait for For anyone whom encountered a similar issue as I did, here's the customizer for test connections to be used with
|
Thanks! @darwin67 I used this in combination with a manual implementation of For people that find this in the future: let pool = ::rocket_contrib::databases::database_config("db_name", rocket.config())
.map(|config| {
// More info: https://github.com/diesel-rs/diesel/issues/2733
let manager = diesel::r2d2::ConnectionManager::new(config.url);
r2d2::Pool::builder()
.connection_customizer(Box::new(TestConnectionCustomizer))
.max_size(config.pool_size)
.build(manager)
}); |
Setup
Versions
Feature Flags
Problem Description
begin_test_transaction
gets flaky when trying to start a transaction in async context (they are not nested).The issue is consistently showing up after around 10 tests which is same as the default pool size for r2d2.
There are no nested transactions as you will be able to see in the code example I shared,
but somehow the
transaction_manager.get_transaction_depth()
is returning non zero, and causing the code to panic.I'm not sure if this is related to Diesel not supporting async or is something else so wanted to share it here and see if there are ways to resolve it.
This doesn't happen when running with
#[test]
and normal synced manner. e.g. seemodels
tests in the repo belowWhat are you trying to accomplish?
Having tests run without flaking randomly
What is the expected output?
Tests shouldn't error out when starting a transaction in async context.
What is the actual output?
Tests failing randomly
https://gist.github.com/darwin67/335def05fe346f637664cb614f42e088
Are you seeing any additional errors?
No
Steps to reproduce
https://github.com/darwin67/async-test-issue
async_dev
,async_test
), and modify theDATABASE_URL
in.env
to fit your local db's credentials fomatmake test
Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: