DEV: ensure queue_time and background_requests are floats (#10901)

GlobalSetting can end up with a String and we expect a Float
This commit is contained in:
Sam 2020-10-13 18:08:38 +11:00 committed by GitHub
parent 32393f72b1
commit a6d9adf346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -330,7 +330,8 @@ module Middleware
end end
if (env["HTTP_DISCOURSE_BACKGROUND"] == "true") && (queue_time = env["REQUEST_QUEUE_SECONDS"]) if (env["HTTP_DISCOURSE_BACKGROUND"] == "true") && (queue_time = env["REQUEST_QUEUE_SECONDS"])
if queue_time > GlobalSetting.background_requests_max_queue_length max_time = GlobalSetting.background_requests_max_queue_length.to_f
if max_time > 0 && queue_time.to_f > max_time
return [ return [
429, 429,
{ {

View File

@ -136,7 +136,7 @@ describe Middleware::AnonymousCache do
end end
) )
global_setting :background_requests_max_queue_length, 1 global_setting :background_requests_max_queue_length, "0.5"
env = { env = {
"HTTP_COOKIE" => "_t=#{SecureRandom.hex}", "HTTP_COOKIE" => "_t=#{SecureRandom.hex}",
@ -161,7 +161,7 @@ describe Middleware::AnonymousCache do
json = JSON.parse(body.join) json = JSON.parse(body.join)
expect(json["extras"]["wait_seconds"]).to be > 4.9 expect(json["extras"]["wait_seconds"]).to be > 4.9
env["REQUEST_QUEUE_SECONDS"] = 0.5 env["REQUEST_QUEUE_SECONDS"] = 0.4
status, _ = app.call(env.dup) status, _ = app.call(env.dup)
expect(status).to eq(200) expect(status).to eq(200)