Skip to content

Specifying a mock DB at runtime and ensuring graceful Local Rocket shutdown w/ tests #2805

Discussion options

You must be logged in to vote

q1/ is there a way to do the same or better w/ existing Rocket capabilities?

You can config databases at runtime with rocket_db_pools as well. It's documented in [Config].

is it possible to trigger a Rocket shutdown when a Client instance is dropped?

No. This is a restriction imposed by Rust and tokio. For async clients, we'd need async Drop, which doesn't exist.

q3/ is there a [better] way of doing this w/ existing Rocket capabilities.

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 a Drop

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@raif-s-naffah
Comment options

Answer selected by raif-s-naffah
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants