Skip to content

Commit

Permalink
Eliminate unnecessary waiting time (#73)
Browse files Browse the repository at this point in the history
If the request for main is finished, sleep will also be finished.

---------

Co-authored-by: Sutou Kouhei <[email protected]>
  • Loading branch information
abetomo and kou authored Apr 10, 2024
1 parent 063ed8c commit a25f04d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 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,21 @@ 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
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))
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 a25f04d

Please sign in to comment.