Skip to content
This repository was archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
add logging to assertPassesWithMultipleAttempts
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaemming committed Aug 2, 2012
1 parent 4ff051b commit 8a3f822
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
File renamed without changes.
10 changes: 9 additions & 1 deletion tests/samsa/client/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
limitations under the License.
"""

import logging
import time

from samsa.client import Client, Message, OFFSET_EARLIEST, OFFSET_LATEST
from samsa.test.integration import (KafkaIntegrationTestCase,
ManagedConsumer, ManagedProducer)


logger = logging.getLogger(__name__)

# class ClientTestCase(unittest2.TestCase):
# def test_produce(self):
# raise NotImplementedError
Expand Down Expand Up @@ -58,12 +61,17 @@ def assertPassesWithMultipleAttempts(self, fn, attempts, timeout=1, backoff=None
backoff = lambda attempt, timeout: timeout

for attempt in xrange(1, attempts + 1):
logger.debug('Starting attempt %s for %s...', attempt, fn)
try:
fn()
logger.info('Passed attempt %s for %s', attempt, fn)
break
except AssertionError:
if attempt < attempts:
time.sleep(backoff(attempt, timeout))
wait = backoff(attempt, timeout)
logger.exception('Failed attempt %s for %s, waiting for %s seconds',
attempt, fn, wait)
time.sleep(wait)
else:
raise

Expand Down

0 comments on commit 8a3f822

Please sign in to comment.