<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,7 +31,7 @@ module GroongaHTTPTestUtils
 
   def teardown_server
     begin
-      shutdown_server
+      shutdown_server if @groonga_pid
     rescue Timeout::Error
     end
     super</diff>
      <filename>test/unit/lib/ruby/groonga-http-test-utils.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,12 +37,16 @@ module GroongaTestUtils
   end
 
   def teardown_server
-    Process.kill(:TERM, @groonga_pid)
-    begin
-      Process.waitpid(@groonga_pid)
-    rescue Errno::ECHILD
+    if @groonga_pid
+      Process.kill(:TERM, @groonga_pid)
+      begin
+        Process.waitpid(@groonga_pid)
+      rescue Errno::ECHILD
+      end
+      @groonga_pid = nil
     end
-    FileUtils.rm_r(@tmp_dir)
+
+    FileUtils.rm_rf(@tmp_dir) if @tmp_dir
   end
 
   private
@@ -71,20 +75,31 @@ module GroongaTestUtils
       exec(@groonga, *arguments)
     end
 
-    Timeout.timeout(1) do
-      loop do
-        begin
-          TCPSocket.new(@address, @port)
-          break
-        rescue SystemCallError
+    begin
+      timeout(1) do
+        loop do
+          begin
+            TCPSocket.new(@address, @port)
+            break
+          rescue SystemCallError
+          end
         end
       end
+    rescue
+      @groonga_pid = nil
+      raise
     end
+  end
 
-    def object_registered
-      current_id = @user_object_start_id
-      @user_object_start_id += 1
-      current_id
-    end
+  def object_registered
+    current_id = @user_object_start_id
+    @user_object_start_id += 1
+    current_id
+  end
+
+  def timeout(seconds, &amp;block)
+    Timeout.timeout(seconds, &amp;block)
+  rescue Timeout::Error
+    raise RuntimeError, &quot;timeout #{seconds}s&quot;, [caller[0]] + $@
   end
 end</diff>
      <filename>test/unit/lib/ruby/groonga-test-utils.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8b074fc8df94c270156d2919b041311c76af1957</id>
    </parent>
  </parents>
  <author>
    <name>Kouhei Sutou</name>
    <email>kou@clear-code.com</email>
  </author>
  <url>http://github.com/groonga/groonga/commit/0c1f8e008e29be2bf7d9e9353f37c7d923dc56d3</url>
  <id>0c1f8e008e29be2bf7d9e9353f37c7d923dc56d3</id>
  <committed-date>2009-11-11T01:34:29-08:00</committed-date>
  <authored-date>2009-11-11T01:30:01-08:00</authored-date>
  <message>improve timeout handling.</message>
  <tree>fdea27704794a9d5323f23716b4800852f23f452</tree>
  <committer>
    <name>Kouhei Sutou</name>
    <email>kou@clear-code.com</email>
  </committer>
</commit>
