From fe9ea6e214feba78c944c8f9c4908680f0dd9e49 Mon Sep 17 00:00:00 2001 From: Yagi Sumiya Date: Mon, 22 Jul 2019 21:05:46 +0900 Subject: [PATCH] Fix behaviors for msgpack --- lib/grntest/error.rb | 1 + lib/grntest/executors/base-executor.rb | 5 ++++- lib/grntest/executors/http-executor.rb | 6 +++++- lib/grntest/executors/standard-io-executor.rb | 3 ++- lib/grntest/response-parser.rb | 8 ++++---- lib/grntest/test-runner.rb | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/grntest/error.rb b/lib/grntest/error.rb index 6da714a..980396f 100644 --- a/lib/grntest/error.rb +++ b/lib/grntest/error.rb @@ -33,6 +33,7 @@ def initialize(type, content, reason) @type = type @content = content @reason = reason + content = content.inspect if type == "msgpack" super("failed to parse <#{@type}> content: #{reason}: <#{content}>") end end diff --git a/lib/grntest/executors/base-executor.rb b/lib/grntest/executors/base-executor.rb index c82d50b..e32a2bd 100644 --- a/lib/grntest/executors/base-executor.rb +++ b/lib/grntest/executors/base-executor.rb @@ -390,6 +390,7 @@ def execute_script(script_path) def extract_command_info(command) @current_command = command + @orig_output_type = command[:output_type] if @current_command.name == "dump" @output_type = "groonga-command" else @@ -585,7 +586,9 @@ def log_query_log_content(content) relative_elapsed_time = "000000000000000" command = statistic.command if command - command[:output_type] = nil if command.output_type == :json + if command.output_type == :json or @orig_output_type.nil? + command[:output_type] = nil + end log_query("\#>#{command.to_command_format}") end statistic.each_operation do |operation| diff --git a/lib/grntest/executors/http-executor.rb b/lib/grntest/executors/http-executor.rb index cee2a54..c08054f 100644 --- a/lib/grntest/executors/http-executor.rb +++ b/lib/grntest/executors/http-executor.rb @@ -29,6 +29,10 @@ def initialize(host, port, context) end def send_command(command) + if @output_type == 'msgpack' + command[:output_type] = 'msgpack' + end + if command.name == "load" send_load_command(command) else @@ -103,7 +107,7 @@ def send_normal_command(command) end def normalize_response_data(command, raw_response_data) - if raw_response_data.empty? or command.output_type == :none + if raw_response_data.empty? or command.output_type == :none or @output_type == "msgpack" raw_response_data else "#{raw_response_data}\n" diff --git a/lib/grntest/executors/standard-io-executor.rb b/lib/grntest/executors/standard-io-executor.rb index 4add769..f7ba71b 100644 --- a/lib/grntest/executors/standard-io-executor.rb +++ b/lib/grntest/executors/standard-io-executor.rb @@ -57,7 +57,8 @@ def read_output(command) if may_slow_command?(command) options[:first_timeout] = @long_read_timeout end - read_all_readable_content(@output, options) + content = read_all_readable_content(@output, options) + @output_type == "msgpack" ? content.sub(/\n\z/, '') : content end MAY_SLOW_COMMANDS = [ diff --git a/lib/grntest/response-parser.rb b/lib/grntest/response-parser.rb index 2f25ec7..9a556b4 100644 --- a/lib/grntest/response-parser.rb +++ b/lib/grntest/response-parser.rb @@ -36,7 +36,7 @@ def initialize(type) def parse(content) case @type when "json", "msgpack" - parse_result(content.chomp) + parse_result(content) else content end @@ -46,14 +46,14 @@ def parse_result(result) case @type when "json" begin - JSON.parse(result) + JSON.parse(result.chomp) rescue JSON::ParserError raise ParseError.new(@type, result, $!.message) end when "msgpack" begin - MessagePack.unpack(result.chomp) - rescue MessagePack::UnpackError, NoMemoryError + MessagePack.unpack(result) + rescue MessagePack::UnpackError, NoMemoryError, EOFError, ArgumentError raise ParseError.new(@type, result, $!.message) end else diff --git a/lib/grntest/test-runner.rb b/lib/grntest/test-runner.rb index ae6f88c..db9f69e 100644 --- a/lib/grntest/test-runner.rb +++ b/lib/grntest/test-runner.rb @@ -590,7 +590,7 @@ def normalize_output(content, options) def normalize_output_structured(type, content, options) response = nil - content = content.chomp + content = content.chomp unless type == "msgpack" if type == "json" and /\A([^(]+\()(.+)(\);)\z/ =~ content jsonp = true jsonp_start = $1 @@ -602,7 +602,7 @@ def normalize_output_structured(type, content, options) begin response = ResponseParser.parse(content, type) rescue ParseError - return $!.message + return $!.message + "\n" end if response.is_a?(Hash)