Skip to content

Commit

Permalink
Eliminate unnecessary waiting time
Browse files Browse the repository at this point in the history
If the request for main is finished, sleep will also be finished.
  • Loading branch information
abetomo committed Apr 10, 2024
1 parent c2531dd commit 173675c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/groonga-query-log/server-verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,22 @@ def verify_command(groonga1_client, groonga2_client, command)
# groonga2 is new Groonga.
response2 = nil
if @options.verify_cancel?
sleep_thread = nil
request = groonga2_client.execute(command) do |response|
response2 = response
sleep_thread.kill if sleep_thread
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)
sleep_thread = Thread.new do
sleep(rand(0..@options.cancel_max_wait))
sleep_thread = nil
end
sleep_thread.join
unless response2
@options.groonga2.create_client do |cancel_client|
cancel_client.execute("request_cancel", id: command.request_id)
end
end
request.wait

Expand Down

0 comments on commit 173675c

Please sign in to comment.