def test_timeout(self): transaction = NetworkTransaction(initial_backoff_seconds=60 * 60, timeout_seconds=60) did_process_exception = False did_throw_exception = True try: transaction.run(self._raise_500_error) did_throw_exception = False except NetworkTimeout: did_process_exception = True self.assertTrue(did_throw_exception) self.assertTrue(did_process_exception)
def test_exception(self): transaction = NetworkTransaction() did_process_exception = False did_throw_exception = True try: transaction.run(self._raise_exception) did_throw_exception = False except Exception as error: # pylint: disable=broad-except did_process_exception = True self.assertEqual(error, self.exception) self.assertTrue(did_throw_exception) self.assertTrue(did_process_exception)
def test_retry(self): transaction = NetworkTransaction(initial_backoff_seconds=0) self.assertEqual(transaction.run(self._raise_500_error), 42) self.assertEqual(self._run_count, 3) self.assertLog([ 'WARNING: Received HTTP status 500 loading "http://example.com/". ' 'Retrying in 0 seconds...\n', 'WARNING: Received HTTP status 500 loading "http://example.com/". ' 'Retrying in 0.0 seconds...\n' ])
def test_convert_404_to_none(self): transaction = NetworkTransaction(return_none_on_404=True) self.assertIsNone(transaction.run(self._raise_404_error))
def test_success(self): transaction = NetworkTransaction() self.assertEqual(transaction.run(lambda: 42), 42)