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

Conversation

abetomo
Copy link
Contributor

@abetomo abetomo commented Apr 5, 2024

Send request_cancel at random and test if it could be cancelled.

Send `request_cancel` at random and test if it could be cancelled.
Comment on lines 431 to 437
parser.on("--cancel-rate=RATE", Float,
"You can specify the rate at which request_cancel is sent." +
"For example, if you specify 0.3 in this option, " +
"send request_cancel with the probability of 3/10.",
"(#{@cancel_rate})") do |rate|
@cancel_rate = rate
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これいらないっす。

対象のリクエスト全部をキャンセル対象でいいです。対象を間引くのは既存の--omit-rateでやります。

def verify_command(groonga1_client, groonga2_client, command)
command["cache"] = "no" if @options.disable_cache?
command["cache"] = "no" if @options.verify_performance?
if @options.cancel_rate > 0 && command.request_id.nil?
command["request_id"] = generate_request_id.to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_sgenerate_request_idでやろうか。

def verify_command(groonga1_client, groonga2_client, command)
command["cache"] = "no" if @options.disable_cache?
command["cache"] = "no" if @options.verify_performance?
if @options.cancel_rate > 0 && command.request_id.nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@options.verify_cancel?を作ってそれを使おうか。

options.verify_cancel?のときはcommand.request_idにあってもそれを上書きでいいです。

Comment on lines 196 to 199
response2 = nil
request = groonga2_client.execute(command) do |response|
response2 = response
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

↓みたいに@options.verify_cancel?じゃないときは既存のコードでよろしく。

Suggested change
response2 = nil
request = groonga2_client.execute(command) do |response|
response2 = response
end
if @options.verify_cancel?
response2 = nil
request2 = groonga2_client.execute(command) do |response|
response2 = response
end
# ...
else
response2 = groonga2_client.execute(command)
end

response2 = response
end
canceled = false
if rand < @options.cancel_rate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

キャンセルするかどうかのランダム性はいらなくて、どのくらい後にキャンセルするかのランダム性は欲しい。すぐにキャンセルだと処理の初期のキャンセルしかテストできない。

たとえば↓みたいな感じ。

sleep(rand(0..10.0))
@options.groonga2.create_client do |cancel_client|
  # ...
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ランダムってそういうことですか。勘違いしてました。

Comment on lines 209 to 212
if canceled
if response2.return_code != -77 # GRN_CANCEL
@events.push([:error, command, 'cancelled and return_code is not GRN_CANCEL(-77)'])
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request_cancelしたら確実にキャンセルできるわけじゃないからこのチェックはいらない。

@options.verify_cancel?のときはreturn_code-77なら結果を比較せずに終了、そうじゃないなら通常の処理、でいいっす。

@abetomo abetomo marked this pull request as ready for review April 5, 2024 06:51
@abetomo
Copy link
Contributor Author

abetomo commented Apr 8, 2024

一通り変更しました。
sleep する時間は固定だと不便なので、オプションで指定できるようにしました。

@kou 確認をお願いします。

@verify_cancel = boolean
end
parser.on("--cancel-max-wait=SECONDS", Float,
"Used with `--verify_cancel`." +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use Markdown:

Suggested change
"Used with `--verify_cancel`." +
"Used with --verify_cancel. " +

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`." +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"before sending `request_cancel`." +
"before sending request_cancel command. " +

"You can specify the maximum number of seconds to wait " +
"before sending `request_cancel`." +
"For example, if you specify 5.0 in this option, " +
"wait randomly between 0~5.0 seconds before sending `request_cancel`.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"wait randomly between 0~5.0 seconds before sending `request_cancel`.",
"wait randomly between 0~5.0 seconds before sending request_cancel command.",

response1 = groonga1_client.execute(command)
response2 = groonga2_client.execute(command)
# `groonga2` is new Groonga.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# `groonga2` is new Groonga.
# groonga2 is new Groonga.

end
request.wait

return if response2.return_code == -77 # GRN_CANCEL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-77は定数で定義しようか。

@verify_cancel = boolean
end
parser.on("--cancel-max-wait=SECONDS", Float,
"Used with --verify_cancel." +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Used with --verify_cancel." +
"Used with --verify_cancel. " +

end

parser.on("--cancel-max-wait=SECONDS", Float,
"Used with --verify_cancel." +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Used with --verify_cancel." +
"Used with --verify_cancel. " +

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." +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"before sending request_cancel command." +
"before sending request_cancel command. " +

"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`.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"wait randomly between 0~5.0 seconds before sending `request_cancel`.",
"wait randomly between 0~5.0 seconds before sending request_cancel command.",

request = groonga2_client.execute(command) do |response|
response2 = response
end
# Randomize timing of sending `request_cancel`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Randomize timing of sending `request_cancel`
# Randomize timing of sending request_cancel

@kou kou merged commit f8f2fea into groonga:master Apr 8, 2024
6 checks passed
@abetomo abetomo deleted the request_cancel_testing branch April 8, 2024 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants