Skip to content

Commit 7c338ff

Browse files
author
rodrigo.nogueira
committed
Marking flaky tests to rerun
1 parent 2a39d88 commit 7c338ff

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

tests/test_client_middleware_digest_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ async def handler(request: Request) -> Response:
13311331
assert auth_algorithms[0] == "MD5-sess" # Not "MD5-SESS"
13321332

13331333

1334-
_REGEX_TIME_THRESHOLD = (0.02, 0.03) # (base=20ms, increment=30ms)
1334+
_REGEX_TIME_THRESHOLD = (0.02, 0.02) # 20ms, +20ms each retry
13351335

13361336

13371337
@pytest.mark.flaky(reruns=3)

tests/test_cookie_helpers.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,28 @@ def test_cookie_pattern_matches_partitioned_attribute(test_string: str) -> None:
637637
assert match.group("key").lower() == "partitioned"
638638

639639

640-
def test_cookie_pattern_performance() -> None:
640+
_COOKIE_PATTERN_TIME_THRESHOLD = (0.02, 0.02) # 20ms, +20ms each retry
641+
642+
643+
@pytest.mark.flaky(reruns=3)
644+
@pytest.mark.parametrize(
645+
"rerun_adjusted_threshold", [_COOKIE_PATTERN_TIME_THRESHOLD], indirect=True
646+
)
647+
def test_cookie_pattern_performance(rerun_adjusted_threshold: float) -> None:
648+
"""Test that the cookie pattern doesn't suffer from ReDoS issues.
649+
650+
This test is marked as flaky because timing can vary on loaded CI machines.
651+
CI failure observed: ~20ms on Windows.
652+
"""
641653
value = "a" + "=" * 21651 + "\x00"
642654
start = time.perf_counter()
643655
match = helpers._COOKIE_PATTERN.match(value)
644-
end = time.perf_counter()
656+
elapsed = time.perf_counter() - start
645657

646-
# If this is taking more than 10ms, there's probably a performance/ReDoS issue.
647-
assert (end - start) < 0.01
648-
# This example shouldn't produce a match either.
658+
assert elapsed < rerun_adjusted_threshold, (
659+
f"Pattern took {elapsed * 1000:.1f}ms, "
660+
f"expected <{rerun_adjusted_threshold * 1000:.0f}ms - potential ReDoS issue"
661+
)
649662
assert match is None
650663

651664

tests/test_web_request.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,15 +600,23 @@ def test_single_forwarded_header() -> None:
600600
assert req.forwarded[0]["proto"] == "identifier"
601601

602602

603-
def test_forwarded_re_performance() -> None:
603+
_FORWARDED_RE_TIME_THRESHOLD = (0.02, 0.02) # 20ms, +20ms each retry
604+
605+
606+
@pytest.mark.flaky(reruns=3)
607+
@pytest.mark.parametrize(
608+
"rerun_adjusted_threshold", [_FORWARDED_RE_TIME_THRESHOLD], indirect=True
609+
)
610+
def test_forwarded_re_performance(rerun_adjusted_threshold: float) -> None:
604611
value = "{" + "f" * 54773 + "z\x00a=v"
605612
start = time.perf_counter()
606613
match = _FORWARDED_PAIR_RE.match(value)
607-
end = time.perf_counter()
614+
elapsed = time.perf_counter() - start
608615

609-
# If this is taking more than 10ms, there's probably a performance/ReDoS issue.
610-
assert (end - start) < 0.01
611-
# This example shouldn't produce a match either.
616+
assert elapsed < rerun_adjusted_threshold, (
617+
f"Regex took {elapsed * 1000:.1f}ms, "
618+
f"expected <{rerun_adjusted_threshold * 1000:.0f}ms - potential ReDoS issue"
619+
)
612620
assert match is None
613621

614622

0 commit comments

Comments
 (0)