Transaction based integration testing with actix-web #1703
Unanswered
OskarPersson
asked this question in
Q&A
Replies: 1 comment
-
First you don't have 2 different pools. You have just one. When you clone you're basically adding a new reference counted pointer to the internal pool. So your test and actix are sharing the same pool. Second you're not committing your Removing the transaction from actix won't help because you can't guarantee they'll be in the same connection either. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When making a web project in Django or Go I'm used to be able to easily create integration tests that are all running against a single real test database (Postgres in my case). With Django this is done automatically when using
django.test.TestCase
where it wraps every test function in a transaction and any request is handled within that same transaction. With Go I can similarly use txdb to achieve the same thing where instead each test gets its own sql.DB, each with their own unique identifier (for example a uuid).Now when using Rust I'm trying to achieve the same thing with sqlx and Actix-web but have not yet succeeded.
For example, with the following Cargo.toml
and main.rs
This does not work since the test and the app are working two different pool instances. Instead I would like to have the handler "one" to have access to the object "test1" that was created in the test itself and thus return "1" since that is the only row available at the time since the inner transaction is rollbacked. The 'inside test transaction' should be rolled back in the rollback issued in the test itself. (And if the test were to fail anywhere, none of the data created should be preserved either since it is all then created in a transaction that is never rollbacked nor commited).
How can I achieve this? Would something similar to txdb as mentioned above work?
Beta Was this translation helpful? Give feedback.
All reactions