Skip to content

Commit

Permalink
WIP: add failing test
Browse files Browse the repository at this point in the history
See #2.
  • Loading branch information
tseaver committed Aug 27, 2020
1 parent f538d40 commit b7347a2
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit b7347a2

Please sign in to comment.