Specifying a mock DB at runtime and ensuring graceful Local Rocket shutdown w/ tests #2805
-
hello there, i'm using a Local Rocket w/ a blocking Client for testing. i also use a mock DB that is created at the start of each test (specifically when Rocket is built) and dropped at the end of said test. the mock DB and its pool are created using my own q1/ is there a way to do the same or better w/ existing Rocket capabilities? using a local Client also means that to cause a graceful Rocket shutdown i have to call the q2/ is it possible to trigger a Rocket shutdown when a Client instance is dropped? finally, to ensure the
( q3/ is there a [better] way of doing this w/ existing Rocket capabilities. thanks in advance for any answers, suggestions, and comments (especially for q3) + cheers; Footnotes |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can config databases at runtime with
No. This is a restriction imposed by Rust and tokio. For
Not with Rocket directly, but I would advocate for either using a more advanced unit testing library that offers set-up and tear-down (like test-context), or if you're only going to be using the blocking struct Client(Option<rocket::local::blocking::Client>);
impl Drop for Client {
fn drop(&mut self) {
self.0.take().unwrap().terminate();
}
} |
Beta Was this translation helpful? Give feedback.
-
i had a closer look at the
it would be nice if such a facility is made available in the future, may be building on Figment's notion of |
Beta Was this translation helpful? Give feedback.
You can config databases at runtime with
rocket_db_pools
as well. It's documented in [Config
].No. This is a restriction imposed by Rust and tokio. For
async
clients, we'd needasync
Drop
, which doesn't exist.Not with Rocket directly, but I would advocate for either using a more advanced unit testing library that offers set-up and tear-down (like test-context), or if you're only going to be using the blocking
Client
, you could consider a wrapper with aDrop
…