White Box Testing
Test your code
   Home      TestPattern-MultithreadingPatterns
Author -  Marc Clifton
Marc is the creator of two open source projets, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.
Marc lives in Philmont, NY.

Multithreading Patterns

Unit testing multithreaded applications is probably one of the most difficult things to do because you have to set up a condition that by its very nature is intended to be asynchronous and therefore non-deterministic.  This topic is probably a major article in itself, so I will provide only a very generic pattern here.  Furthermore, to perform many threading tests correctly, the unit tester application must itself execute tests as separate threads so that the unit tester isn't disabled when one thread ends up in a wait state.

The Signalled Pattern

This test verifies that a worker thread eventually signals the main thread or another worker thread, which then completes its task.  This may be dependent on other services (another good use of mock objects) and the data on which both threads are operating, thus involving other test patterns as well.

The Deadlock-Resolution Pattern

This test, which is probably very complicated to establish because it requires a very thorough understanding of the worker threads, verifies that deadlocks are resolved.