Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upShared Test Transactions #900
Comments
This comment has been minimized.
|
The solution I've been using in crates.io is to set the connection pool size to 1, but I agree that it'd be nice to make it easier. I do not want to implement |
sgrif
added
the
enhancement
label
May 13, 2017
This comment has been minimized.
fluffysquirrels
commented
Aug 28, 2017
|
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mcasper commentedMay 11, 2017
When running tests in a multithreaded environment (like running tests against a webserver), currently the only way to ensure that your test database is clean across threads is to drop/truncate for every test. This works fine, but is tedious, and it would be nicer if connections and their test transactions could be shared, so that data is all localized and automatically cleaned up.
One way to accomplish this that I've been thinking about is to implement
Syncfor connections andConnectionforArc<T: Connection>, allowing pointers to a shared connection to be passed around and data within a test transaction to be visible. I know we've previously talked about not wanting to implementSyncfor connections because they're not meant to be passed around, which is why I'd want to hide this away behind atestsortestingfeature, included only in[dev-dependencies].Some changes would be necessary in other supporting libraries (like r2d2/r2d2-diesel for example), but could lead to code like the following for testing (example using Rocket):
If we like this, I'm happy to take on the feature work