Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add test for retries of timeouts.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Aug 3, 2015
1 parent 2bdb14a commit 12b9d93
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions go/apps/http_api_nostream/tests/test_vumi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,14 +828,17 @@ def test_post_inbound_message_ignored(self):
req = yield self.push_calls.get()
self.assertEqual(req, None)

def _patch_http_request_full(self, exception_class):
def _patch_http_request_full(self, exception_class, once=False):
from go.apps.http_api_nostream import vumi_app
http_calls = []

def raiser(*args, **kw):
if once:
patch.restore()
http_calls.append((args, kw))
raise exception_class()
self.patch(vumi_app, 'http_request_full', raiser)

patch = self.patch(vumi_app, 'http_request_full', raiser)
return http_calls

@inlineCallbacks
Expand Down Expand Up @@ -865,7 +868,7 @@ def test_post_inbound_message_500_response(self):
self.assertTrue('500' in warning_log)

@inlineCallbacks
def test_post_inbound_message_500_schedule_retry(self):
def test_post_inbound_message_500_schedules_retry(self):
retry_url, retry_calls = yield self.start_retry_server()
yield self.start_app_worker({
'http_retry_api': retry_url,
Expand Down Expand Up @@ -895,7 +898,34 @@ def test_post_inbound_message_500_schedule_retry(self):
self.assertEqual(retry_msg['message_id'], msg['message_id'])

@inlineCallbacks
def test_post_inbound_message_500_schedule_retry_failed_500(self):
def test_post_inbound_message_timeout_schedules_retry(self):
retry_url, retry_calls = yield self.start_retry_server()
yield self.start_app_worker({
'http_retry_api': retry_url,
})
msg_d = self.app_helper.make_dispatch_inbound(
'in 1', message_id='1', conv=self.conversation)

self._patch_http_request_full(HttpTimeoutError, once=True)

# catch and check retry
retry = yield retry_calls.get()
retry_msg = self.assert_retry(retry, self.get_message_url())
retry.setResponseCode(200)
retry.finish()

with LogCatcher(log_level=logging.INFO) as lc:
msg = yield msg_d

self.assertEqual(lc.messages(), [
"Successfully scheduled retry of request [account: u'test-0-user'"
", url: '%s']" % self.get_message_url(),
])

self.assertEqual(retry_msg['message_id'], msg['message_id'])

@inlineCallbacks
def test_post_inbound_message_500_retry_fails_with_500(self):
retry_url, retry_calls = yield self.start_retry_server()
yield self.start_app_worker({
'http_retry_api': retry_url,
Expand Down Expand Up @@ -924,7 +954,7 @@ def test_post_inbound_message_500_schedule_retry_failed_500(self):
])

@inlineCallbacks
def test_post_inbound_message_500_schedule_retry_exception(self):
def test_post_inbound_message_500_retry_fails_with_exception(self):
retry_url, retry_calls = yield self.start_retry_server()
yield self.start_app_worker({
'http_retry_api': retry_url,
Expand Down

0 comments on commit 12b9d93

Please sign in to comment.