-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Send `request_cancel` at random and test if it could be cancelled.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_s
はgenerate_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? |
There was a problem hiding this comment.
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
にあってもそれを上書きでいいです。
response2 = nil | ||
request = groonga2_client.execute(command) do |response| | ||
response2 = response | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
↓みたいに@options.verify_cancel?
じゃないときは既存のコードでよろしく。
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ランダムってそういうことですか。勘違いしてました。
if canceled | ||
if response2.return_code != -77 # GRN_CANCEL | ||
@events.push([:error, command, 'cancelled and return_code is not GRN_CANCEL(-77)']) | ||
end |
There was a problem hiding this comment.
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
なら結果を比較せずに終了、そうじゃないなら通常の処理、でいいっす。
一通り変更しました。 @kou 確認をお願いします。 |
@verify_cancel = boolean | ||
end | ||
parser.on("--cancel-max-wait=SECONDS", Float, | ||
"Used with `--verify_cancel`." + |
There was a problem hiding this comment.
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:
"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`." + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# `groonga2` is new Groonga. | |
# groonga2 is new Groonga. |
end | ||
request.wait | ||
|
||
return if response2.return_code == -77 # GRN_CANCEL |
There was a problem hiding this comment.
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." + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Used with --verify_cancel." + | |
"Used with --verify_cancel. " + |
end | ||
|
||
parser.on("--cancel-max-wait=SECONDS", Float, | ||
"Used with --verify_cancel." + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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." + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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`.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Randomize timing of sending `request_cancel` | |
# Randomize timing of sending request_cancel |
Send
request_cancel
at random and test if it could be cancelled.