I have a class, which works with string dictionary. One method is for initializing dictionary, another one is for adding new pair to dictionary and third method is for concatenating dictionary into string.
I'd like to unit-test if its thread-safe, by running init-adding-adding-*-adding-finalizing methods in different threads simultaneously. A new instance of the class is created before usage, dictionary is not static. So i'd like to know for sure, if its safe.
Afaik, testing threads in unit-tests is not that good idea. Instead, i had found a CHESS, which is designed with exactly the same purpose: http://blog.decarufel.net/2009/05/how-to-test-your-multi-threaded-code.html
However, looking like its outdated. Any modern alternatives/suggestions on this field?
As an alternative, you could take a look at using the ConcurrentDictionary type, which would abstract away these particular multithreading worries.
However, if you want to continue using your own mechanism (or if you want a general answer to the question of how to test multi-threaded code), it looks from this post that CHESS is by no means obsolete. The underlying technology - multithreading - has not changed at all to my knowledge since this tool was first released, so unless you have a specific problem using it, it's perfectly reasonable to go ahead.
The last checkin to the project was in October of 2012. I wouldn't say it's all that outdated.
http://chesstool.codeplex.com/SourceControl/list/changesets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With