Kouhei Sutou
null+****@clear*****
Wed May 25 16:33:13 JST 2016
Kouhei Sutou 2016-05-25 16:33:13 +0900 (Wed, 25 May 2016) New Revision: e0fefa513c5b2f32a32e5a5ff686b05c90156ebf https://github.com/groonga/grntest/commit/e0fefa513c5b2f32a32e5a5ff686b05c90156ebf Message: Clean timeout related directives * timeout -> timeout for one command * read_timeout -> timeout for reading response of one command * It's used only in StandardIOExecutor * long_read_timeout -> timeout for reading response of one heavy command * It's used only in StandardIOExecutor long_timeout is removed. It's incompatible change but nobody isn't used. Maybe. Modified files: lib/grntest/executors/base-executor.rb lib/grntest/executors/http-executor.rb lib/grntest/executors/standard-io-executor.rb lib/grntest/test-runner.rb Modified: lib/grntest/executors/base-executor.rb (+47 -32) =================================================================== --- lib/grntest/executors/base-executor.rb 2016-05-25 15:46:25 +0900 (07293e3) +++ lib/grntest/executors/base-executor.rb 2016-05-25 16:33:13 +0900 (7f9e20e) @@ -40,7 +40,8 @@ module Grntest @pending_load_command = nil @current_command_name = nil @output_type = nil - @long_timeout = default_long_timeout + @read_timeout = default_read_timeout + @long_read_timeout = default_long_read_timeout @context = context @custom_important_log_levels = [] end @@ -186,17 +187,18 @@ module Grntest FileUtils.cp_r(source.to_s, destination.to_s) end - def execute_directive_timeout(line, content, options) - timeout, = options + def timeout_value(key, line, input, default) + new_value = nil + invalid_value_p = false - case timeout + case input when "default" - @context.timeout =****@conte*****_timeout + new_value = default when nil invalid_value_p = true else begin - @context.timeout = Float(timeout) + new_value = Float(input) rescue ArgumentError invalid_value_p = true end @@ -204,32 +206,39 @@ module Grntest if invalid_value_p log_input(line) - message = "timeout must be number or 'default': <#{timeout}>" - log_error("#|e| [timeout] #{message}") + message = "#{key} must be number or 'default': <#{input}>" + log_error("#|e| [#{key}] #{message}") + nil + else + new_value end end - def execute_directive_long_timeout(line, content, options) - long_timeout, = options - invalid_value_p = false - case long_timeout - when "default" - @long_timeout = default_long_timeout - when nil - invalid_value_p = true - else - begin - @long_timeout = Float(long_timeout) - rescue ArgumentError - invalid_value_p = true - end - end + def execute_directive_timeout(line, content, options) + timeout, = options + new_value = timeout_value("timeout", + line, + timeout, + @context.default_timeout) + @context.timeout = new_value unless new_value.nil? + end - if invalid_value_p - log_input(line) - message = "long-timeout must be number or 'default': <#{long_timeout}>" - log_error("#|e| [long-timeout] #{message}") - end + def execute_directive_read_timeout(line, content, options) + timeout, = options + new_value = timeout_value("read-timeout", + line, + timeout, + default_read_timeout) + @read_timeout = new_value unless new_value.nil? + end + + def execute_directive_long_read_timeout(line, content, options) + timeout, = options + new_value = timeout_value("long-read-timeout", + line, + timeout, + default_long_read_timeout) + @long_read_timeout = new_value unless new_value.nil? end def execute_directive_on_error(line, content, options) @@ -323,8 +332,10 @@ module Grntest execute_directive_copy_path(line, content, options) when "timeout" execute_directive_timeout(line, content, options) - when "long-timeout" - execute_directive_long_timeout(line, content, options) + when "read-timeout" + execute_directive_read_timeout(line, content, options) + when "long-read-timeout" + execute_directive_long_read_timeout(line, content, options) when "on-error" execute_directive_on_error(line, content, options) when "omit" @@ -430,7 +441,7 @@ module Grntest def read_all_readable_content(output, options={}) content = "" - first_timeout = options[:first_timeout] || @timeout + first_timeout = options[:first_timeout] || @read_timeout timeout = first_timeout while IO.select([output], [], [], timeout) break if output.eof? @@ -530,7 +541,11 @@ module Grntest output end - def default_long_timeout + def default_read_timeout + 3 + end + + def default_long_read_timeout 180 end end Modified: lib/grntest/executors/http-executor.rb (+3 -8) =================================================================== --- lib/grntest/executors/http-executor.rb 2016-05-25 15:46:25 +0900 (c1700e1) +++ lib/grntest/executors/http-executor.rb 2016-05-25 16:33:13 +0900 (ae956ee) @@ -22,15 +22,10 @@ require "grntest/executors/base-executor" module Grntest module Executors class HTTPExecutor < BaseExecutor - def initialize(host, port, context, options={}) + def initialize(host, port, context) super(context) @host = host @port = port - if options.key?(:read_timeout) - @read_timeout = options[:read_timeout] - else - @read_timeout = 3 - end end def send_command(command) @@ -79,7 +74,7 @@ module Grntest request.content_type = "application/json; charset=UTF-8" request.body = body response = Net::HTTP.start(@host, @port) do |http| - http.read_timeout = @read_timeout + http.read_timeout =****@conte***** http.request(request) end normalize_response_data(command, response.body) @@ -88,7 +83,7 @@ module Grntest def send_normal_command(command) url = "http://#{@host}:#{@port}#{command.to_uri_format}" begin - open(url, :read_timeout => @read_timeout) do |response| + open(url, :read_timeout => @context.timeout) do |response| normalize_response_data(command, response.read) end rescue SystemCallError Modified: lib/grntest/executors/standard-io-executor.rb (+1 -1) =================================================================== --- lib/grntest/executors/standard-io-executor.rb 2016-05-25 15:46:25 +0900 (34cd150) +++ lib/grntest/executors/standard-io-executor.rb 2016-05-25 16:33:13 +0900 (bed109a) @@ -57,7 +57,7 @@ module Grntest def read_output(command) options = {} if may_slow_command?(command) - options[:first_timeout] = @long_timeout + options[:first_timeout] = @long_read_timeout end read_all_readable_content(@output, options) end Modified: lib/grntest/test-runner.rb (+2 -5) =================================================================== --- lib/grntest/test-runner.rb 2016-05-25 15:46:25 +0900 (f47329e) +++ lib/grntest/test-runner.rb 2016-05-25 16:33:13 +0900 (c668af2) @@ -339,14 +339,11 @@ call chdir("#{context.temporary_directory_path}") command_line = groonga_http_command(host, port, pid_file_path, context, spawn_options) pid = nil - options = { - :read_timeout => @tester.timeout, - } - options[:read_timeout] = nil if****@teste***** begin pid = Process.spawn(env, *command_line, spawn_options) + executor = nil begin - executor = Executors::HTTPExecutor.new(host, port, context, options) + executor = Executors::HTTPExecutor.new(host, port, context) begin executor.ensure_groonga_ready rescue -------------- next part -------------- HTML����������������������������...Download