From 944d3419652bc715807e9c411147f6a1e94870ce Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Wed, 25 Nov 2026 22:06:06 +0000 Subject: [PATCH 1/8] refactor(core): let Metric.for_web take a config Ruby's RequestMetrics takes the config it reads, defaulting to Config.instance. Metric.for_web now does the same, defaulting to Judoscale's config. Co-Authored-By: Claude --- judoscale/core/metric.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/judoscale/core/metric.py b/judoscale/core/metric.py index 0153bac..bde3bac 100644 --- a/judoscale/core/metric.py +++ b/judoscale/core/metric.py @@ -3,6 +3,8 @@ from datetime import datetime, timezone from typing import Optional, Tuple +from judoscale.core.config import Config +from judoscale.core.config import config as judoconfig from judoscale.core.logger import logger # Adapted from https://github.com/scoutapp/scout_apm_python/blob/86d14920a59a7a3b5dfffe680586646ee29bdd7a/src/scout_apm/core/web_requests.py#L139-L162 # noqa: E501 @@ -60,7 +62,11 @@ def new(cls, start_ms: int, **kwargs) -> "Metric": return cls(timestamp=now, value=latency_ms, **kwargs) @classmethod - def for_web(cls, header_value: str) -> Optional["Metric"]: + def for_web( + cls, + header_value: str, + config: Optional[Config] = None, + ) -> Optional["Metric"]: """ Parse the X-Request-Start header value and return a Metric instance. @@ -73,8 +79,15 @@ def for_web(cls, header_value: str) -> Optional["Metric"]: Calculate how long a request has been waiting to be handled, log and return a Metric instance. + + config: + The Judoscale config to read settings from. Defaults to + Judoscale's own. """ + if config is None: + config = judoconfig + if header_value.startswith("t="): header_value = header_value[2:] From 57eebcbb3213b158eacd483d98a3b3fa91e8da93 Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Wed, 25 Nov 2026 20:14:57 +0000 Subject: [PATCH 2/8] feat(core): add the MAX_REQUEST_SIZE_BYTES setting Some web servers, such as waitress, read the whole request body before they call the app. A slow upload of a large body then shows up as queue time that says nothing about capacity. Metric.for_web now also takes the request's Content-Length, and returns no queue time metric for a body over the config's MAX_REQUEST_SIZE_BYTES, as Ruby's RequestMetrics does. A missing or invalid Content-Length counts as no body. App time and utilization are still recorded. The setting defaults to 100_000 as in Ruby, and is reported with the rest of the config. Set it to None to count every request. Co-Authored-By: Claude --- judoscale/core/config.py | 7 ++++++- judoscale/core/metric.py | 20 +++++++++++++++++++- tests/test_config.py | 19 +++++++++++++++++-- tests/test_metrics.py | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) diff --git a/judoscale/core/config.py b/judoscale/core/config.py index 2f598e4..0676400 100644 --- a/judoscale/core/config.py +++ b/judoscale/core/config.py @@ -6,7 +6,11 @@ from judoscale.core.logger import logger from judoscale.core.platform import Platform -DEFAULTS = {"REPORT_INTERVAL_SECONDS": 10, "LOG_LEVEL": "WARN"} +DEFAULTS = { + "LOG_LEVEL": "WARN", + "REPORT_INTERVAL_SECONDS": 10, + "MAX_REQUEST_SIZE_BYTES": 100_000, +} class Config(UserDict): @@ -60,6 +64,7 @@ def for_report(self): return { "log_level": self["LOG_LEVEL"], "report_interval_seconds": self["REPORT_INTERVAL_SECONDS"], + "max_request_size_bytes": self["MAX_REQUEST_SIZE_BYTES"], } def _prepare_logging(self): diff --git a/judoscale/core/metric.py b/judoscale/core/metric.py index bde3bac..55635c6 100644 --- a/judoscale/core/metric.py +++ b/judoscale/core/metric.py @@ -1,7 +1,7 @@ import time from dataclasses import dataclass from datetime import datetime, timezone -from typing import Optional, Tuple +from typing import Optional, Tuple, Union from judoscale.core.config import Config from judoscale.core.config import config as judoconfig @@ -65,6 +65,7 @@ def new(cls, start_ms: int, **kwargs) -> "Metric": def for_web( cls, header_value: str, + content_length: Optional[Union[int, str]] = None, config: Optional[Config] = None, ) -> Optional["Metric"]: """ @@ -80,6 +81,14 @@ def for_web( Calculate how long a request has been waiting to be handled, log and return a Metric instance. + Return None when the request's Content-Length is over the config's + MAX_REQUEST_SIZE_BYTES. Some web servers, such as waitress, read the + whole request body before they call the app, so a slow upload of a + large body shows up as queue time that says nothing about capacity. + + content_length: + The request's Content-Length header, as a string or an int. + config: The Judoscale config to read settings from. Defaults to Judoscale's own. @@ -88,6 +97,15 @@ def for_web( if config is None: config = judoconfig + try: + request_size = int(content_length or 0) + except ValueError: + request_size = 0 + + max_request_size_bytes = config["MAX_REQUEST_SIZE_BYTES"] + if max_request_size_bytes is not None and request_size > max_request_size_bytes: + return None + if header_value.startswith("t="): header_value = header_value[2:] diff --git a/tests/test_config.py b/tests/test_config.py index 9761a94..800572d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -192,14 +192,29 @@ def test_for_report(self): "JUDOSCALE_URL": "https://api.example.com", } config = Config.initialize(fake_env) - assert config.for_report == {"log_level": "WARN", "report_interval_seconds": 10} + assert config.for_report == { + "log_level": "WARN", + "report_interval_seconds": 10, + "max_request_size_bytes": 100_000, + } - config.update({"LOG_LEVEL": "ERROR", "REPORT_INTERVAL_SECONDS": 20}) + config.update( + { + "LOG_LEVEL": "ERROR", + "REPORT_INTERVAL_SECONDS": 20, + "MAX_REQUEST_SIZE_BYTES": None, + } + ) assert config.for_report == { "log_level": "ERROR", "report_interval_seconds": 20, + "max_request_size_bytes": None, } + def test_max_request_size_bytes_defaults_to_100k(self): + config = Config(Unknown(""), {}) + assert config["MAX_REQUEST_SIZE_BYTES"] == 100_000 + def test_update(self): fake_env = { "DYNO": "worker.1", diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 427cedf..d69e113 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -2,7 +2,10 @@ from pytest import approx +from judoscale.core.config import Config +from judoscale.core.config import config as judoconfig from judoscale.core.metric import Metric +from judoscale.core.platform import Unknown class TestMetricsForWeb: @@ -42,6 +45,38 @@ def test_negative_value(self): def test_garbage_value(self): assert Metric.for_web("t=abc") is None + def test_request_over_max_size(self): + request_start = str(round(time.time() * 1000)) + config = Config(Unknown(""), {}) + + assert Metric.for_web(request_start, "100001", config=config) is None + assert Metric.for_web(request_start, 100_001, config=config) is None + + def test_request_up_to_max_size(self): + request_start = str(round(time.time() * 1000)) + config = Config(Unknown(""), {}) + + assert Metric.for_web(request_start, None, config=config) is not None + assert Metric.for_web(request_start, "", config=config) is not None + assert Metric.for_web(request_start, "512", config=config) is not None + assert Metric.for_web(request_start, 512, config=config) is not None + assert Metric.for_web(request_start, "100000", config=config) is not None + assert Metric.for_web(request_start, "not-a-number", config=config) is not None + + def test_no_max_request_size(self): + request_start = str(round(time.time() * 1000)) + config = Config(Unknown(""), {}) + config.update({"MAX_REQUEST_SIZE_BYTES": None}) + + assert Metric.for_web(request_start, "10000000", config=config) is not None + + def test_max_request_size_from_judoscale_config(self, monkeypatch): + request_start = str(round(time.time() * 1000)) + monkeypatch.setitem(judoconfig, "MAX_REQUEST_SIZE_BYTES", 1_000) + + assert Metric.for_web(request_start, "1000") is not None + assert Metric.for_web(request_start, "1001") is None + class TestMetricsForQueueDepth: def test_for_queue_depth(self): From 108fd55327cf9519ee2c76438ec571123025258d Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Wed, 25 Nov 2026 20:15:02 +0000 Subject: [PATCH 3/8] feat(django): ignore queue time for requests with large bodies CONTENT_LENGTH comes from the WSGI environ as a string, which may be empty or absent. Co-Authored-By: Claude --- judoscale/django/middleware.py | 3 ++- sample-apps/django_sample/tests/tests.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/judoscale/django/middleware.py b/judoscale/django/middleware.py index 358d289..1c89d26 100644 --- a/judoscale/django/middleware.py +++ b/judoscale/django/middleware.py @@ -26,8 +26,9 @@ def __init__(self, get_response): def __call__(self, request): with self.track_utilization(): request_start_header = request.META.get("HTTP_X_REQUEST_START", "") + content_length = request.META.get("CONTENT_LENGTH") - if metric := Metric.for_web(request_start_header): + if metric := Metric.for_web(request_start_header, content_length): self.collector.add(metric) reporter.ensure_running() diff --git a/sample-apps/django_sample/tests/tests.py b/sample-apps/django_sample/tests/tests.py index 6cace58..cdbede8 100644 --- a/sample-apps/django_sample/tests/tests.py +++ b/sample-apps/django_sample/tests/tests.py @@ -76,3 +76,24 @@ def test_reporter_captures_metrics(self): self.assertEqual(metrics[2].measurement, "qt") self.assertGreaterEqual(metrics[2].value, 0) self.assertGreater(metrics[2].timestamp, now) + + def test_reporter_skips_queue_time_for_large_requests(self): + now = datetime.datetime.now().timestamp() + + response = client.post( + "/", + data=b"x" * 100_001, + content_type="application/octet-stream", + HTTP_X_REQUEST_START=f"{now}", + HTTP_X_REQUEST_ID="00000000-0000-0000-0000-000000000000", + ) + + self.assertEqual(response.status_code, 200) + self.assertEqual(reporter.is_running, True) + self.assertEqual(utilization_tracker.is_started, True) + + # no queue time metrics gathered, only app time & utilization + metrics = reporter.all_metrics + self.assertEqual(len(metrics), 2) + self.assertEqual(metrics[0].measurement, "up") + self.assertEqual(metrics[1].measurement, "at") From fcbf9f101f6cb6173b6dac73c16eb919571f4a16 Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Wed, 25 Nov 2026 20:15:04 +0000 Subject: [PATCH 4/8] feat(flask): ignore queue time for requests with large bodies Werkzeug parses the header into request.content_length, an int, or None when the request has no Content-Length. The sample app's index route only accepts GET, so its test sends the large body with a GET. Co-Authored-By: Claude --- judoscale/flask/judoscale.py | 2 +- sample-apps/flask_sample/tests.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/judoscale/flask/judoscale.py b/judoscale/flask/judoscale.py index 527a25c..4caa796 100644 --- a/judoscale/flask/judoscale.py +++ b/judoscale/flask/judoscale.py @@ -16,7 +16,7 @@ def store_queue_time_metric(collector: WebMetricsCollector): def inner(): request_start_header = request.headers.get("x-request-start", "") - if metric := Metric.for_web(request_start_header): + if metric := Metric.for_web(request_start_header, request.content_length): collector.add(metric) reporter.ensure_running() diff --git a/sample-apps/flask_sample/tests.py b/sample-apps/flask_sample/tests.py index 1d83cf1..9b619f3 100644 --- a/sample-apps/flask_sample/tests.py +++ b/sample-apps/flask_sample/tests.py @@ -82,6 +82,28 @@ def test_reporter_captures_metrics(self): self.assertGreaterEqual(metrics[2].value, 0) self.assertGreater(metrics[2].timestamp, now) + def test_reporter_skips_queue_time_for_large_requests(self): + now = time.time() + + response = client.get( + "/", + data=b"x" * 100_001, + headers={ + "X-Request-Start": f"{round(now * 1000)}", + "X-Request-Id": "00000000-0000-0000-0000-000000000000", + }, + ) + + self.assertEqual(response.status_code, 200) + self.assertEqual(reporter.is_running, True) + self.assertEqual(utilization_tracker.is_started, True) + + # no queue time metrics gathered, only app time & utilization + metrics = reporter.all_metrics + self.assertEqual(len(metrics), 2) + self.assertEqual(metrics[0].measurement, "up") + self.assertEqual(metrics[1].measurement, "at") + if __name__ == "__main__": unittest.main() From a2606f8a7c56a1dd3f03e1445a5ee10af02a240e Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Wed, 25 Nov 2026 20:15:05 +0000 Subject: [PATCH 5/8] feat(asgi): ignore queue time for requests with large bodies The middleware now looks both headers up in a dict of the request's headers. The loop it replaces stopped at X-Request-Start, so it would have missed a Content-Length that came after it. With two X-Request-Start headers, the last one now wins instead of the first. ASGI servers such as uvicorn call the app as soon as the headers arrive, so they don't add upload time to queue time themselves. The check is here to match Ruby, which applies its cutoff on every Rack server. Co-Authored-By: Claude --- judoscale/asgi/middleware.py | 12 ++++++------ sample-apps/fastapi_sample/tests.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/judoscale/asgi/middleware.py b/judoscale/asgi/middleware.py index cf185dc..20548ea 100644 --- a/judoscale/asgi/middleware.py +++ b/judoscale/asgi/middleware.py @@ -40,12 +40,12 @@ async def __call__(self, scope, receive, send): return await self.app(scope, receive, send) with self.track_utilization(): - for header, value in scope["headers"]: - if header.lower() == b"x-request-start": - request_start = value.decode() - if metric := Metric.for_web(request_start): - self.collector.add(metric) - break + headers = {name.lower(): value for name, value in scope["headers"]} + request_start = headers.get(b"x-request-start", b"").decode() + content_length = headers.get(b"content-length", b"").decode() + + if metric := Metric.for_web(request_start, content_length): + self.collector.add(metric) reporter.ensure_running() diff --git a/sample-apps/fastapi_sample/tests.py b/sample-apps/fastapi_sample/tests.py index 36b6381..89c6c54 100644 --- a/sample-apps/fastapi_sample/tests.py +++ b/sample-apps/fastapi_sample/tests.py @@ -81,6 +81,29 @@ def test_reporter_captures_metrics(self): self.assertGreaterEqual(metrics[2].value, 0) self.assertGreater(metrics[2].timestamp, now) + def test_reporter_skips_queue_time_for_large_requests(self): + now = time.time() + + response = client.request( + "GET", + "/", + content=b"x" * 100_001, + headers={ + "X-Request-Start": f"{round(now * 1000)}", + "X-Request-Id": "00000000-0000-0000-0000-000000000000", + }, + ) + + self.assertEqual(response.status_code, 200) + self.assertEqual(reporter.is_running, True) + self.assertEqual(utilization_tracker.is_started, True) + + # no queue time metrics gathered, only app time & utilization + metrics = reporter.all_metrics + self.assertEqual(len(metrics), 2) + self.assertEqual(metrics[0].measurement, "up") + self.assertEqual(metrics[1].measurement, "at") + if __name__ == "__main__": unittest.main() From 5a13a740c8af0a33c9b548f7775430512594eb91 Mon Sep 17 00:00:00 2001 From: Alexander Kavanaugh Date: Wed, 25 Nov 2026 20:15:13 +0000 Subject: [PATCH 6/8] docs: describe MAX_REQUEST_SIZE_BYTES Co-Authored-By: Claude --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 6cdbb98..c2eb135 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ Optionally, you can customize Judoscale in `settings.py`: JUDOSCALE = { # Log level defaults to ENV["LOG_LEVEL"] or "INFO". "LOG_LEVEL": "DEBUG", + # Leave requests with a body over this many bytes out of queue time. Some + # web servers read the whole body before the app sees the request, so a + # slow upload shows up as queue time. Defaults to 100_000 (100 KB). + # Set to None to count every request. + "MAX_REQUEST_SIZE_BYTES": 100_000, } ``` @@ -87,6 +92,11 @@ Optionally, you can override Judoscale's own configuration via your application' JUDOSCALE = { # Log level defaults to ENV["LOG_LEVEL"] or "INFO". "LOG_LEVEL": "DEBUG", + # Leave requests with a body over this many bytes out of queue time. Some + # web servers read the whole body before the app sees the request, so a + # slow upload shows up as queue time. Defaults to 100_000 (100 KB). + # Set to None to count every request. + "MAX_REQUEST_SIZE_BYTES": 100_000, } ``` @@ -129,6 +139,12 @@ Optionally, you can override Judoscale's configuration by passing in extra confi app.add_middleware(FastAPIRequestQueueTimeMiddleware, extra_config={"LOG_LEVEL": "DEBUG"}) ``` +Requests with a body over `MAX_REQUEST_SIZE_BYTES` (100_000 bytes, or 100 KB, by default) are left out of queue time. Set it to `None` to count every request: + +```py +app.add_middleware(FastAPIRequestQueueTimeMiddleware, extra_config={"MAX_REQUEST_SIZE_BYTES": None}) +``` + ## Other ASGI frameworks Judoscale also provides middleware classes for Starlette and Quart. You can use them with From e2002039727adbb65ed4aa4e9f3d817ca17e69c2 Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 1 Dec 2026 12:43:14 +0000 Subject: [PATCH 7/8] revert(asgi): count queue time for large requests again ASGI servers such as uvicorn call the app as soon as the headers arrive, so a slow upload never shows up as queue time there. Skipping large requests on ASGI only dropped good samples. Amp-Thread-ID: https://ampcode.com/threads/T-386281c6-cbb1-4bf2-b363-f53338fdcd89 Co-authored-by: Adam McCrea --- README.md | 6 ------ judoscale/asgi/middleware.py | 12 ++++++------ sample-apps/fastapi_sample/tests.py | 23 ----------------------- 3 files changed, 6 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index c2eb135..509f529 100644 --- a/README.md +++ b/README.md @@ -139,12 +139,6 @@ Optionally, you can override Judoscale's configuration by passing in extra confi app.add_middleware(FastAPIRequestQueueTimeMiddleware, extra_config={"LOG_LEVEL": "DEBUG"}) ``` -Requests with a body over `MAX_REQUEST_SIZE_BYTES` (100_000 bytes, or 100 KB, by default) are left out of queue time. Set it to `None` to count every request: - -```py -app.add_middleware(FastAPIRequestQueueTimeMiddleware, extra_config={"MAX_REQUEST_SIZE_BYTES": None}) -``` - ## Other ASGI frameworks Judoscale also provides middleware classes for Starlette and Quart. You can use them with diff --git a/judoscale/asgi/middleware.py b/judoscale/asgi/middleware.py index 20548ea..cf185dc 100644 --- a/judoscale/asgi/middleware.py +++ b/judoscale/asgi/middleware.py @@ -40,12 +40,12 @@ async def __call__(self, scope, receive, send): return await self.app(scope, receive, send) with self.track_utilization(): - headers = {name.lower(): value for name, value in scope["headers"]} - request_start = headers.get(b"x-request-start", b"").decode() - content_length = headers.get(b"content-length", b"").decode() - - if metric := Metric.for_web(request_start, content_length): - self.collector.add(metric) + for header, value in scope["headers"]: + if header.lower() == b"x-request-start": + request_start = value.decode() + if metric := Metric.for_web(request_start): + self.collector.add(metric) + break reporter.ensure_running() diff --git a/sample-apps/fastapi_sample/tests.py b/sample-apps/fastapi_sample/tests.py index 89c6c54..36b6381 100644 --- a/sample-apps/fastapi_sample/tests.py +++ b/sample-apps/fastapi_sample/tests.py @@ -81,29 +81,6 @@ def test_reporter_captures_metrics(self): self.assertGreaterEqual(metrics[2].value, 0) self.assertGreater(metrics[2].timestamp, now) - def test_reporter_skips_queue_time_for_large_requests(self): - now = time.time() - - response = client.request( - "GET", - "/", - content=b"x" * 100_001, - headers={ - "X-Request-Start": f"{round(now * 1000)}", - "X-Request-Id": "00000000-0000-0000-0000-000000000000", - }, - ) - - self.assertEqual(response.status_code, 200) - self.assertEqual(reporter.is_running, True) - self.assertEqual(utilization_tracker.is_started, True) - - # no queue time metrics gathered, only app time & utilization - metrics = reporter.all_metrics - self.assertEqual(len(metrics), 2) - self.assertEqual(metrics[0].measurement, "up") - self.assertEqual(metrics[1].measurement, "at") - if __name__ == "__main__": unittest.main() From b6fa921ce5f92b6f80d44c92ac6bc0f4afb1a33b Mon Sep 17 00:00:00 2001 From: Amp Date: Tue, 1 Dec 2026 12:43:48 +0000 Subject: [PATCH 8/8] fix(core): coerce MAX_REQUEST_SIZE_BYTES in Config.update Metric.for_web compares the setting to every request's size, so a string such as one read from an environment variable raised a TypeError on every request, and False dropped queue time for any request with a body. Config.update now converts a numeric string to an int and False to None, which turns the cutoff off as in Ruby. Any other invalid value logs a warning and falls back to the default. Amp-Thread-ID: https://ampcode.com/threads/T-386281c6-cbb1-4bf2-b363-f53338fdcd89 Co-authored-by: Adam McCrea --- judoscale/core/config.py | 21 +++++++++++++++++++++ tests/test_config.py | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/judoscale/core/config.py b/judoscale/core/config.py index 0676400..da6d808 100644 --- a/judoscale/core/config.py +++ b/judoscale/core/config.py @@ -52,6 +52,7 @@ def update(self, new_config: Mapping): self[k].update(v) else: self[k] = v + self._coerce_max_request_size_bytes() self._prepare_logging() def merge(self, new_config: Mapping): @@ -67,6 +68,26 @@ def for_report(self): "max_request_size_bytes": self["MAX_REQUEST_SIZE_BYTES"], } + def _coerce_max_request_size_bytes(self): + # Metric.for_web compares this to every request's size, so a value of + # the wrong type would fail every request. + value = self["MAX_REQUEST_SIZE_BYTES"] + + if value is None or value is False: + # False turns the cutoff off, as in Ruby. + self["MAX_REQUEST_SIZE_BYTES"] = None + elif isinstance(value, int) and not isinstance(value, bool): + pass + elif isinstance(value, str) and value.strip().isdigit(): + self["MAX_REQUEST_SIZE_BYTES"] = int(value) + else: + default = DEFAULTS["MAX_REQUEST_SIZE_BYTES"] + logger.warning( + f"Invalid MAX_REQUEST_SIZE_BYTES {value!r}, using {default}. " + "Set it to a number of bytes, or None to count every request." + ) + self["MAX_REQUEST_SIZE_BYTES"] = default + def _prepare_logging(self): log_level = logging.getLevelName(self["LOG_LEVEL"].upper()) logger.setLevel(log_level) diff --git a/tests/test_config.py b/tests/test_config.py index 800572d..2bcc324 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -215,6 +215,20 @@ def test_max_request_size_bytes_defaults_to_100k(self): config = Config(Unknown(""), {}) assert config["MAX_REQUEST_SIZE_BYTES"] == 100_000 + def test_update_coerces_max_request_size_bytes(self, caplog): + config = Config(Unknown(""), {}) + + config.update({"MAX_REQUEST_SIZE_BYTES": "5000"}) + assert config["MAX_REQUEST_SIZE_BYTES"] == 5000 + + config.update({"MAX_REQUEST_SIZE_BYTES": False}) + assert config["MAX_REQUEST_SIZE_BYTES"] is None + + for invalid in ["lots", True, 1.5]: + config.update({"MAX_REQUEST_SIZE_BYTES": invalid}) + assert config["MAX_REQUEST_SIZE_BYTES"] == 100_000 + assert "Invalid MAX_REQUEST_SIZE_BYTES 'lots'" in caplog.text + def test_update(self): fake_env = { "DYNO": "worker.1",