[Django] #27112: django.test.client.Client doesn't support timeouts

26 views
Skip to first unread message

Django

unread,
Aug 23, 2016, 9:40:29 AM8/23/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+-----------------------------
Reporter: roboslone | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.10
Severity: Normal | Keywords: testing,timeout
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+-----------------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/27112>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 23, 2016, 9:43:36 AM8/23/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------

Reporter: roboslone | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.10
Severity: Normal | Resolution:

Keywords: testing,timeout | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by roboslone):

* 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>

Django

unread,
Aug 23, 2016, 11:31:57 AM8/23/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------
Reporter: roboslone | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: testing,timeout | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Aug 23, 2016, 12:07:48 PM8/23/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------
Reporter: roboslone | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: testing,timeout | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

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>

Django

unread,
Aug 23, 2016, 12:32:19 PM8/23/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------
Reporter: roboslone | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: testing,timeout | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

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>

Django

unread,
Aug 23, 2016, 12:46:45 PM8/23/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------
Reporter: roboslone | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: testing,timeout | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

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>

Django

unread,
Aug 24, 2016, 4:49:35 PM8/24/16
to django-...@googlegroups.com
#27112: django.test.client.Client doesn't support timeouts
-----------------------------------+--------------------------------------
Reporter: roboslone | Owner: nobody
Type: New feature | Status: closed

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution: wontfix

Keywords: testing,timeout | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages