--
Ticket URL: <https://code.djangoproject.com/ticket/27112>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> I'm trying to test my middleware for replay processing (same request was
> issued twice, because first attempt failed due to client timeout). I need
> some control over timeouts in django.test.client.Client. Is it possible
> to implement requests-like (http://docs.python-
> requests.org/en/master/user/advanced/#timeouts) kwarg for timeout?
New description:
I'm trying to test my middleware for replay processing (same request was
issued twice, because first attempt failed due to client timeout). I need
some control over timeouts in django.test.client.Client. Would it be
possible to implement requests-like (http://docs.python-
requests.org/en/master/user/advanced/#timeouts) kwarg for timeout?
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
Have you considered using mocking to raise a timeout exception? I don't
think requiring the run time of a test suite to be increased by the
duration of a timeout is a ideal.
Feel free to ask on [wiki:TicketClosingReasons our support channels]
and/or the DevelopersMailingList if you need other ideas or if you want to
propose this feature, but it doesn't seem needed to me at first glance.
--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:2>
Comment (by roboslone):
Replying to [comment:2 timgraham]:
> Have you considered using mocking to raise a timeout exception? I don't
think requiring the run time of a test suite to be increased by the
duration of a timeout is a ideal.
>
> Feel free to ask on [wiki:TicketClosingReasons our support channels]
and/or the DevelopersMailingList if you need other ideas or if you want to
propose this feature, but it doesn't seem needed to me at first glance.
I need to simulate timeout on client side, not on server side, that's the
whole point. My application is hosted on several machines behind load
balancer and I need to test app's behaviour under balancer's
timeouts/retries.
--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:3>
Comment (by timgraham):
Oh, sorry, I have no idea about that. If you provided an implementation
that would help the discussion as I really have no idea if this is a good
idea or even feasible. The mailing list is a better for discussion since
more people are reading that than this ticket tracker.
--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:4>
Comment (by roboslone):
Replying to [comment:4 timgraham]:
> Oh, sorry, I have no idea about that. If you provided an implementation
that would help the discussion as I really have no idea if this is a good
idea or even feasible. The mailing list is a better for discussion since
more people are reading that than this ticket tracker.
{{{requests}}} uses python's {{{Queue}}}
(https://docs.python.org/3.5/library/queue.html#queue.Queue.get) for that.
I will write on mailing list, thanks for the link. Could you remove
"wontfix" for now?
--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:5>
Comment (by roboslone):
To anyone with similar use case, I was able to test client timeouts with
modified {{{LiveServerTestCase}}}. Discussion can be found in this thread:
https://groups.google.com/forum/#!topic/django-developers/PofmsTQ-YGs
{{{tl;dr}}}
Use following code to define {{{ThreadedLiveServerTestCase}}}:
{{{#!python
from django.test.testcases import LiveServerThread,
QuietWSGIRequestHandler
from django.core.servers.basehttp import WSGIServer
from socketserver import ThreadingMixIn
class ThreadedWSGIServer(ThreadingMixIn, WSGIServer):
pass
class ThreadedLiveServerThread(LiveServerThread):
def _create_server(self, port):
return ThreadedWSGIServer((self.host, port),
QuietWSGIRequestHandler)
class ThreadedLiveServerTestCase(LiveServerTestCase):
@classmethod
def _create_server_thread(cls, host, possible_ports,
connections_override):
return ThreadedLiveServerThread(
host,
possible_ports,
cls.static_handler,
connections_override=connections_override,
)
}}}
And use {{{requests}}} to query backends:
{{{#!python
import requests
from requests.exceptions import Timeout
...
with self.assertRaises(Timeout):
requests.get(self.live_server_url + '/something', timeout=1.0)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27112#comment:6>