Skip to content

Isolated tests running in their own transactions #759

Answered by davidpdrsn
OskarPersson asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think thats possible since extractors (things that implement FromRequest) most be fully owned. That is, they cannot contain borrowed data. sqlx::Transaction borrows the connection so it cannot be accessed via an extractor. I'm not very familiar with sqlx so dunno if there is a workaround.

Also, in general I would strongly recommend against wrapping each test in a transaction. I've attempted to do something like that in the past but kept running into issues, like the one you're facing. Instead I would recommend giving each test its own totally separate database. This is how I do it at work and it works great. We basically have some test helpers that creates a database with a random…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@OskarPersson
Comment options

@davidpdrsn
Comment options

@OskarPersson
Comment options

@davidpdrsn
Comment options

@OskarPersson
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants