lipanski / mockito

HTTP mocking for Rust!
MIT License
670 stars 57 forks source link

Code coverage with tarpaulin #84

Closed valnoel closed 1 year ago

valnoel commented 5 years ago

Hello!

I'm trying to integrate mockito in some unit tests for the rs_amqp_worker project (see the related PR), and I cannot get through the code coverage computed with tarpaulin.

My issue is that the coverage randomly fails (on Travis and locally) running one of the unit tests that uses mockito (only them). It's not always the same test that makes it fail, and sometimes the coverage completes correctly.

I suspected a concurrent issue due to the static mockito::server_url(), but I tried some workaround (distributing my mocks on different HTTP resources) but it doesn't change anything.

However, I have no problem executing a multi-threaded cargo test on the project.

Would you have any idea on how to fix this? Thanks!

lipanski commented 5 years ago

I'm not familiar with tarpaulin or how it's built but one thing to note is that Mockito tests are actually run sequentially - not in parallel. this is handled internally via a thread_local mutex. the mutex is there to allow all non-mockito tests to still run in parallel. given the current architecture, it was not possible to run Mockito tests in parallel at all, hence all this.

it could be that tarpaulin is somehow getting stuck on the mutex (in which case the test would timeout). but as I see in your Travis build, the only hint at the error is a "segfault". could you try to narrow this down - maybe run the tool in debug mode, to produce a more detailed error message?

you could also try raising the issue on the tarpaulin side or checking their other segfault issues. I'm not saying that Mockito might not be the culprit here, but maybe they have an idea of what exactly might cause this.

lipanski commented 1 year ago

should probably be fixed by one of the recent releases https://github.com/lipanski/mockito/releases (0.32+)