test: stabilize proxy tests#1762
Conversation
4e5b9f3 to
95b285f
Compare
| if expected_proxy_logsize != 0: | ||
| # request passed through successfully | ||
| wait_for_stdout( | ||
| proxy_process, | ||
| lambda text: "POST" in text and "200 OK" in text, | ||
| timeout, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Bug: The wait_for_stdout call in proxy_test_finally hardcodes a check for "200 OK", causing tests that expect non-200 responses (like 407) to time out.
Severity: HIGH
Suggested Fix
The wait_for_stdout predicate should be made more flexible. Instead of hardcoding a check for "200 OK", it could be parameterized or adjusted to handle different expected outcomes, such as successful requests or failed authentication. One option is to pass the expected status string or a custom predicate function into proxy_test_finally.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: tests/proxy.py#L146-L153
Potential issue: The new logic in `proxy_test_finally` waits for "POST" and "200 OK" in
the proxy's stdout when `expected_proxy_logsize` is not zero. However, the
`test_proxy_auth` test case expects a "407 Proxy Authentication Required" response, not
a "200 OK". Because the predicate in `wait_for_stdout` can never be satisfied in this
scenario, the test will wait for the full timeout period and then fail with a
`TimeoutError`. This makes the test helper inflexible for scenarios involving
non-successful HTTP responses.
Also affects:
tests/proxy.py:110~110
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bc69cde. Configure here.
| proxy_process.terminate() | ||
| stdout_bytes, _ = proxy_process.communicate() | ||
| stdout = stdout_bytes.decode("utf-8", errors="replace") | ||
| proxy_process.wait(timeout=timeout) |
There was a problem hiding this comment.
Proxy process leaks when pre-termination assertions fail
Medium Severity
The assert wait_for(...) on line 142 and wait_for_stdout(...) on line 148 can both raise exceptions (AssertionError and TimeoutError respectively) before proxy_process.terminate() on line 154 is reached. Since proxy_test_finally is the sole cleanup mechanism for the proxy process (called from finally blocks with no other atexit/fixture fallback), a failure in either wait leaks the mitmdump process. The old code always called terminate() + communicate() before any assertions, guaranteeing cleanup regardless of test outcome.
Reviewed by Cursor Bugbot for commit bc69cde. Configure here.


Proxy-related tests have been failing quite often lately
Replace the hardcoded 0.5s sleep with a wait loop that gives
mitmdumpup to 10s to get a response from the mock server. This should help in busy CI environments where runners may be under load and processes can be delayed.