gabrielfalcao / HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module

Home Page:https://httpretty.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTPretty does not respect timeouts anymore

mariojonke opened this issue · comments

Since latest release (1.1.2) socket timeouts are not raised anymore.

The problem can be reproduced by the following test:

import requests
from threading import Event

from httpretty import httprettified
from httpretty import HTTPretty

@httprettified
def test_read_timeout():
    event = Event()
    uri = "http://example.com"

    def my_callback(request, url, headers):
        event.wait(10)
        return 200, headers, "Received"

    HTTPretty.register_uri(HTTPretty.GET, uri, body=my_callback)
    requests.get(uri, timeout=(1, 0.1))
    event.set()

The test should actually raise a TimeoutError but instead waits until my_callback completes execution.
It seems that the problem is at httppretty/core.py#700, where joining the request callback thread with None will wait infinitely until the callback finishes. So the socket.timeout will actually never be raised.

Thanks @mariojonke for the report and the test case 🙏🏽

Relates to the patch from #426

thread_timeout = 0 # https://github.com/gabrielfalcao/HTTPretty/issues/426

fixed on release 1.1.3