Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behaviors for msgpack #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/grntest/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/grntest/executors/base-executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand Down
6 changes: 5 additions & 1 deletion lib/grntest/executors/http-executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/grntest/executors/standard-io-executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
8 changes: 4 additions & 4 deletions lib/grntest/response-parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/grntest/test-runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down