« Return to Thread: TDD for multi-threaded programs

Re: TDD for multi-threaded programs

by Ferenczi, Szabolcs :: Rate this Message:

Reply to Author | View in Thread

On Wed, 2 May 2007, Lasse Koskela wrote:

> Having said that, I have to note that using Thread#getState() is not
> something you can absolutely rely on as the behavior isn't guaranteed
> to be the same on all platforms. That is, it can be a useful tool for
> debugging and test-driving but not ideal for regression (unit)
> testing.

Thanks for your comment. It does not really affect the basic idea of how
to TDD code for multi-threaded programs. If state inquiry is not available
or not safe to use, you can always set some path tracing flags and check
that instead. The main issue is that you make the test case deterministic,
set up the scenario for the functionality to be implemented with help of
tester threads and implement the functionality just like you do for a
sequential program. I did use tracing flags when I TDDd Perl
multi-threaded code and I could not find any appropriate state checking
queries on threads there. The method I have demonstrated works with the
path tracing flags as well.

The same remark holds for interrupting threads. I used interrupting in
this demo to keep the functional test as simple as possible. I did not
find any possibility to use interrupts in Perl, so I simply provided the
required input to the suspended thread to terminate, after I have checked
that the expected behaviour is there.

Best Regards,
Szabolcs

 « Return to Thread: TDD for multi-threaded programs