Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add failing test #8

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions repoze/retry/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ def test_conflict_not_raised_start_response_called(self):
('200 OK', _MINIMAL_HEADERS, None))
self.assertEqual(result, [b'hello'])

def test_conflict_not_raised_start_response_called_at_first_chunk(self):
application = LazyApplication(conflicts=1)
retry = self._makeOne(application, tries=4,
retryable=(self.ConflictError,))
result = unwind(retry(self._makeEnv(), self._dummy_start_response))
self.assertEqual(application.called, 1)
self.assertEqual(self._dummy_start_response_result,
('200 OK', _MINIMAL_HEADERS, None))
self.assertEqual(result, [b'hello'])

def test_alternate_retryble_exception(self):
application = DummyApplication(conflicts=1, exception=Retryable,
call_start_response=True)
Expand Down Expand Up @@ -440,6 +450,23 @@ def __call__(self, environ, start_response):
self.app_iter = self.iter_factory([b'hello'])
return self.app_iter

class LazyApplication(DummyApplication):
def __call__(self, environ, start_response):
if self.called < self.conflicts:
self.called += 1
raise self.exception
istream = environ.get('wsgi.input')
if istream is not None:
chunks = []
chunk = istream.read(1024)
while chunk:
chunks.append(chunk)
chunk = istream.read(1024)
self.wsgi_input = b''.join(chunks)
if self.call_start_response:
start_response('200 OK', _MINIMAL_HEADERS)
yield b'hello'

class BrokenPipeAppIter(object):
closed = False

Expand Down