On Thu, May 03, 2007 at 11:54:37AM +0900, John Miller wrote:
> I'm writing a script that calls an external program using popen.  The
> program has the potential to run forever, but I what to kill it if it
> has not found a solution in 10 seconds.  I have therefore set up a
> Thread that 'sleep's for 10 seconds and then calls Process.kill on the
> PID.  I've been successful in mocking out the popen call and Process,
> but I am having trouble writing a test that ensures the thread will be
> killed.  Test::Unit seems to ignore/override threads.
> 
> Can anyone give me some advice on how to test threads?  It would be
> really nice if I didn't have to actually wait the full 10 seconds
> either.

I suggest you post your code; modify it so the process it calls via popen is
"sleep 15" or something like that.

I've never had problems testing threads; but I *have* had problems when
testing code which forks another process (which may include popen).

The problem was that the child process inherited all the Test::Unit stuff,
including its atexit handler. I think the solution was to call exit! at the
end of the child, but I can't remember exactly.