Parallel testing with a shared server and code coverage #1598
jtwaleson
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
|
Thanks @jtwaleson for sharing! In Loco, we also have the option to run tests with async builds. You can check it out in the docs here. Have you tried it?
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I started seriously using the test framework a couple of weeks ago but was a bit annoyed that it got slow. I noticed all tests were using
serial. You're restoring a clean database with every test and tests can only run one at a time, while I have 16 cores on my machine. This is great for consistency, but not for speed.I wanted to see if I could run my test suite parallel with a shared_server that only gets initialized once and here is the outcome. As a bonus, I also got code coverage to work (see below).
Now you can run tests like this:
Note that you will need the
tokio-shared-rtcrate as a dev depency:cargo add --dev tokio-shared-rt, as otherwise the test framework will shut down the tokio runtime after a test, and it might still be in use by other tests.Now all of my tests run in parallel and within 40 seconds instead of 70s. Also, as my app is supposed to be a high traffic multi-tenant environment (single db), the tests also help catch cross-tenant bugs. If another test modified my data, the asserts or snapshots will show it.
Whenever I need a serial test, I tag it with
serialand these run after (or before) all of the parallel tests.As an extra, I've also started using cargo-llvm-cov and now get beautiful code coverage output like this:

That actually took a bit of time to set up correctly, as I'm also using cranelift and the wild linker for fast compilation times.
It took a couple of days of tweaking but I'm now super happy with my setup!
Beta Was this translation helpful? Give feedback.
All reactions