--test-threads=1 runs tests successfully under macOS but not under Windows. The tests use a shared mocked server, thus the need to make sure only single test is executed at a time.
Running my tests under macOS without using the above flag causes tests fail randomly (as expected). Using the flag all the tests pass.
However, on Windows7 regardless of flag being used it seems tests are run in parallel and they fail (each time different one fails implying that some kind of race is happening)
To not rely on the flag, I then implemented suggested mutex approach by @nrc to lock the shared web server by each thread. The tests ran successfully on macOS without the
--test-threads=1, but they showed the same failing behavior under Windows!
This is the version of tests before using
mutex. And this is after using
I wanted to conclude that my
mutex solution was incorrect since didn’t work under Windows, but then macOS suggests the opposite.
So my questions are:
--test-threads=1behaves differently on each platform (tried with
msvcvariants of compiler)
- Any suggestion on how I can go about fixing this on Windows?
I am using
mockito crate which starts the mock server on a fixed port. Each tests creates a mock server which responds with different content. This causes the issue if multiple tests are connecting to same port and expecting different results.
I came across this issue because my tests passed on travis CI but not appveyor.
Thanks in advance,