Unit test for thread safe-ness?

后端 未结 9 1780
你的背包
你的背包 2020-11-30 19:32

I\'ve written a class and many unit test, but I did not make it thread safe. Now, I want to make the class thread safe, but to prove it and use TDD, I want to write some fa

9条回答
  •  既然无缘
    2020-11-30 20:11

    There are two products that can help you there:

    • Microsoft Chess
    • Typemock Racer

    Both check for deadlocks in your code (via unit test) and I think Chess checks for race conditions as well.

    Using both tools is easy - you write a simple unit test and the run your code several times and check if deadlocks/race conditions is possible in your code.

    Edit: Google has released a tool that checks for race condition in runtime (not during tests) that called thread-race-test.
    it won't find all of the race conditions because it only analyse the current run and not all of the possible scenarios like the tool above but it might help you find the race condition once it happens.

    Update: Typemock site no longer had a link to Racer, and it was not been updated in the last 4 years. I guess the project was closed.

提交回复
热议问题