2007/5/3, John Miller <jfmiller28 / yahoo.com>:
> Greetings All:
>
> 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.
>
> John Miller
>
> --
> Posted via http://www.ruby-forum.com/.
>

How about using the timeout module?

require 'timeout'
begin
  Timeout::timeout(10) do
    #do stuff...
  end
rescue Timeout::Error
  puts "Cut short"
else
  puts "Ran until the end"
end

Regards,
Raf