From a6d9adf346774d7a1a7021c796631cad9b07f2ee Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 13 Oct 2020 18:08:38 +1100 Subject: [PATCH] DEV: ensure queue_time and background_requests are floats (#10901) GlobalSetting can end up with a String and we expect a Float --- lib/middleware/anonymous_cache.rb | 3 ++- spec/components/middleware/anonymous_cache_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/middleware/anonymous_cache.rb b/lib/middleware/anonymous_cache.rb index c57bafbc5af..6fc70fb720d 100644 --- a/lib/middleware/anonymous_cache.rb +++ b/lib/middleware/anonymous_cache.rb @@ -330,7 +330,8 @@ module Middleware end 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 [ 429, { diff --git a/spec/components/middleware/anonymous_cache_spec.rb b/spec/components/middleware/anonymous_cache_spec.rb index dbe344a3c38..dd410bb86b7 100644 --- a/spec/components/middleware/anonymous_cache_spec.rb +++ b/spec/components/middleware/anonymous_cache_spec.rb @@ -136,7 +136,7 @@ describe Middleware::AnonymousCache do end ) - global_setting :background_requests_max_queue_length, 1 + global_setting :background_requests_max_queue_length, "0.5" env = { "HTTP_COOKIE" => "_t=#{SecureRandom.hex}", @@ -161,7 +161,7 @@ describe Middleware::AnonymousCache do json = JSON.parse(body.join) 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) expect(status).to eq(200)