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

Test for successful cancellation #70

Merged
merged 6 commits into from
Apr 8, 2024
Merged
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
23 changes: 23 additions & 0 deletions lib/groonga-query-log/command/run-regression-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def initialize
@debug_rewrite = false
@omit_rate = 0.0
@max_limit = -1
@verify_cancel = false
@cancel_max_wait = 5.0

@care_order = true
@ignored_drilldown_keys = []
Expand Down Expand Up @@ -426,6 +428,20 @@ def create_option_parser
"(#{@notifier_options[:mail_only_on_failure]})") do |boolean|
@notifier_options[:mail_only_on_failure] = boolean
end
parser.on("--[no-]verify-cancel",
"Verify cancellation",
"(#{@verify_cancel})") do |boolean|
@verify_cancel = boolean
end
parser.on("--cancel-max-wait=SECONDS", Float,
"Used with --verify_cancel. " +
"You can specify the maximum number of seconds to wait " +
"before sending request_cancel command. " +
"For example, if you specify 5.0 in this option, " +
"wait randomly between 0~5.0 seconds before sending request_cancel command.",
"(#{@cancel_max_wait})") do |seconds|
@cancel_max_wait = seconds
end
parser
end

Expand Down Expand Up @@ -478,6 +494,8 @@ def tester_options
:verify_performance => @verify_performance,
:performance_verfifier_options => @performance_verfifier_options,
:read_timeout => @read_timeout,
:verify_cancel => @verify_cancel,
:cancel_max_wait => @cancel_max_wait,
}
directory_options.merge(options)
end
Expand Down Expand Up @@ -945,6 +963,11 @@ def verify_server(test_log_path, query_log_path, &callback)
command_line << "--read-timeout"
command_line << @options[:read_timeout].to_s
end
if @options[:verify_cancel]
command_line << "--verify_cancel"
command_line << "--cancel-max-wait"
command_line << @options[:cancel_max_wait].to_s
end
verify_server = VerifyServer.new
same = verify_server.run(command_line, &callback)
@n_executed_commands = verify_server.n_executed_commands
Expand Down
16 changes: 16 additions & 0 deletions lib/groonga-query-log/command/verify-server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ def create_parser
@options.max_limit = limit
end

parser.on("--[no-]verify-cancel",
"Verify cancellation",
"(#{@options.verify_cancel?})") do |boolean|
@options.verify_cancel = boolean
end

parser.on("--cancel-max-wait=SECONDS", Float,
"Used with --verify_cancel. " +
"You can specify the maximum number of seconds to wait " +
"before sending request_cancel command. " +
"For example, if you specify 5.0 in this option, " +
"wait randomly between 0~5.0 seconds before sending request_cancel command.",
"(#{@options.cancel_max_wait})") do |seconds|
@options.cancel_max_wait = seconds
end

create_parser_performance(parser)

parser.separator("")
Expand Down
41 changes: 40 additions & 1 deletion lib/groonga-query-log/server-verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@

module GroongaQueryLog
class ServerVerifier
GRN_CANCEL = -77

attr_reader :n_executed_commands
def initialize(options)
@options = options
@queue = SizedQueue.new(@options.request_queue_size)
@events = Queue.new
@n_executed_commands = 0
@request_id_counter = 0
end

def verify(input, &callback)
Expand Down Expand Up @@ -167,9 +170,15 @@ def stop?
@options.stop_on_failure? and failed?
end

def generate_request_id
(@request_id_counter += 1).to_s
end

def verify_command(groonga1_client, groonga2_client, command)
command["cache"] = "no" if @options.disable_cache?
command["cache"] = "no" if @options.verify_performance?
command["request_id"] = generate_request_id if @options.verify_cancel?

if @options.max_limit >= 0 and command["limit"]
limit = command["limit"].to_i
if limit >= 0
Expand All @@ -181,8 +190,26 @@ def verify_command(groonga1_client, groonga2_client, command)
command["output_type"] = "json"
rewrite_filter(command, "filter")
rewrite_filter(command, "scorer")

response1 = groonga1_client.execute(command)
response2 = groonga2_client.execute(command)
# groonga2 is new Groonga.
response2 = nil
if @options.verify_cancel?
request = groonga2_client.execute(command) do |response|
response2 = response
end
# Randomize timing of sending request_cancel command
sleep(rand(0..@options.cancel_max_wait))
@options.groonga2.create_client do |cancel_client|
cancel_client.execute("request_cancel", id: command.request_id)
end
request.wait

return if response2.return_code == GRN_CANCEL
else
response2 = groonga2_client.execute(command)
end

compare_options = {
:care_order => @options.care_order,
:ignored_drilldown_keys => @options.ignored_drilldown_keys,
Expand Down Expand Up @@ -326,6 +353,8 @@ class Options
attr_writer :debug_rewrite
attr_writer :omit_rate
attr_accessor :max_limit
attr_writer :verify_cancel
attr_writer :cancel_max_wait
def initialize
@groonga1 = GroongaOptions.new
@groonga2 = GroongaOptions.new
Expand Down Expand Up @@ -361,6 +390,8 @@ def initialize
@debug_rewrite = false
@omit_rate = 0.0
@max_limit = -1
@verify_cancel = false
@cancel_max_wait = 5.0
end

def request_queue_size
Expand Down Expand Up @@ -460,6 +491,14 @@ def debug_rewrite?
def omit_rate
@omit_rate
end

def verify_cancel?
@verify_cancel
end

def cancel_max_wait
@cancel_max_wait
end
end

class GroongaOptions
Expand Down