开发者

Testing asynchronous capabilities of a django + tornado application

开发者 https://www.devze.com 2023-03-25 15:00 出处:网络
I\'m using django-on-tornado to build an application that is similar to the chat applicatoin proposed. All tutorials are focused on how to run a django application over tornado server, but how can I开

I'm using django-on-tornado to build an application that is similar to the chat applicatoin proposed. All tutorials are focused on how to run a django application over tornado server, but how can I开发者_如何学Go test an asynchronous feature that depends on tornado?

My current test does the following:

  • Starts a thread that sleeps for some time than sends a chat message
  • Do a request to ask for messages
  • When request ends, check that message arrived and that time elapsed is compatible with thread sleep time

When I run the test (with manage.py test), I get an "AttributeError: 'WSGIRequest' object has no attribute '_tornado_handler'", which is expected, since the _tornado_handler property of the request is set in runtornado command.

Is there a way to make this setup so that I can test the asynchronous feature? I use nose with django_nose plugin for tests.


Actually django-on-tornado does not anyhow change the manage.py test command of Django, so the Tornado is invoked only via runtornado. You will need to add command to manage.py called something like "testtornado" with implementation similar to https://github.com/koblas/django-on-tornado/blob/master/myproject/django_tornado/management/commands/runtornado.py - it should set up _tornado_handler and proceed with launching your test code.

0

精彩评论

暂无评论...
验证码 换一张
取 消