Improve testing to avoid failures when running test cases in parallel #2110

As title