Skip to content

Commit

Permalink
bustage fix so that monkeypatches in test_transaction_executor puts t…
Browse files Browse the repository at this point in the history
…ime.sleep back to what it was, r=twobraids
  • Loading branch information
peterbe committed Jan 27, 2012
1 parent 3842585 commit f0ee79e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
5 changes: 3 additions & 2 deletions socorro/unittest/cron/testWeeklyReportsPartitions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
import psycopg2
from psycopg2.extensions import TRANSACTION_STATUS_IDLE
from socorro.app.generic_app import main
Expand All @@ -23,7 +24,7 @@
}


class TestClass:
class TestClass(unittest.TestCase):

def setUp(self):
assert 'test' in databaseName.default, databaseName.default
Expand Down Expand Up @@ -66,4 +67,4 @@ def test_run_weeklyReportsPartitions(self):
# check that something was written to the mock_bucket
cursor = self.conn.cursor()
cursor.execute('select count(*) from mock_bucket;')
assert cursor.fetchone()
self.assertTrue(cursor.fetchone())
38 changes: 23 additions & 15 deletions socorro/unittest/database/testTransactionExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,20 @@ def mock_sleep(n):
_sleep_count.append(n)

# monkey patch the sleep function from inside transaction_executor
_orig_sleep = socorro.database.transaction_executor.time.sleep
socorro.database.transaction_executor.time.sleep = mock_sleep

executor(mock_function)
self.assertTrue(_function_calls)
self.assertEqual(commit_count, 1)
self.assertEqual(rollback_count, 0)
self.assertTrue(mock_logging.warnings)
self.assertEqual(len(mock_logging.warnings), 5)
self.assertTrue(len(_sleep_count) > 10)
try:
executor(mock_function)
self.assertTrue(_function_calls)
self.assertEqual(commit_count, 1)
self.assertEqual(rollback_count, 0)
self.assertTrue(mock_logging.warnings)
self.assertEqual(len(mock_logging.warnings), 5)
self.assertTrue(len(_sleep_count) > 10)
finally:
socorro.database.transaction_executor.time.sleep = _orig_sleep


def test_operation_error_with_postgres_with_backoff_with_rollback(self):
required_config = Namespace()
Expand Down Expand Up @@ -277,13 +282,16 @@ def mock_sleep(n):
_sleep_count.append(n)

# monkey patch the sleep function from inside transaction_executor
_orig_sleep = socorro.database.transaction_executor.time.sleep
socorro.database.transaction_executor.time.sleep = mock_sleep

executor(mock_function)
self.assertTrue(_function_calls)
self.assertEqual(commit_count, 1)
self.assertEqual(rollback_count, 5)
self.assertTrue(mock_logging.warnings)
self.assertEqual(len(mock_logging.warnings), 5)
self.assertTrue(len(_sleep_count) > 10)

try:
executor(mock_function)
self.assertTrue(_function_calls)
self.assertEqual(commit_count, 1)
self.assertEqual(rollback_count, 5)
self.assertTrue(mock_logging.warnings)
self.assertEqual(len(mock_logging.warnings), 5)
self.assertTrue(len(_sleep_count) > 10)
finally:
socorro.database.transaction_executor.time.sleep = _orig_sleep

0 comments on commit f0ee79e

Please sign in to comment.