Beispiel #1
0
 def test_set_retry_params(self):
     """Test retry_params setter method with RetryParams instance."""
     gcs = self.test_class(mock.sentinel.credentials)
     new_params = common.RetryParams()
     gcs.retry_params = new_params
     self.assertIsNot(common.RetryParams.get_default(), gcs.retry_params)
     self.assertIs(new_params, gcs.retry_params)
Beispiel #2
0
 def test_init_default(self):
     """Test that default values for new instances are as expected."""
     params = common.RetryParams()
     self.assertEqual(5, params.max_retries)
     self.assertEqual(1, params.initial_delay)
     self.assertEqual(32, params.max_backoff)
     self.assertEqual(2, params.backoff_factor)
     self.assertTrue(params.randomize)
Beispiel #3
0
 def test_init_values(self):
     """Test that we can initialize values for new instances."""
     params = common.RetryParams(mock.sentinel.max_retries, 2, 3, 4, False)
     self.assertEqual(mock.sentinel.max_retries, params.max_retries)
     self.assertEqual(2, params.initial_delay)
     self.assertEqual(3, params.max_backoff)
     self.assertEqual(4, params.backoff_factor)
     self.assertFalse(params.randomize)
Beispiel #4
0
 def test_retry_specify_params_self(self):
     """Test that we can set retry parameter on self attribute."""
     function = mock.Mock(__name__='fake',
                          side_effect=gcs_errors.RequestTimeout())
     retries = self.retries + 1
     slf = mock.Mock(_retry_params=common.RetryParams(retries, 0))
     wrapper = common.retry(function)
     self.assertRaises(gcs_errors.RequestTimeout, wrapper, slf)
     # Initial call plus all the retries
     self.assertEqual(retries + 1, function.call_count)
Beispiel #5
0
 def test_set_default_using_instance(self):
     """Test that get_default always returns the same instance."""
     first_params = common.RetryParams.get_default()
     first_params_dict = dict(vars(common.RetryParams.get_default()))
     new_params = common.RetryParams(1, 2, 3, 4, False)
     common.RetryParams.set_default(new_params)
     second_params = common.RetryParams.get_default()
     self.assertIs(first_params, second_params)
     self.assertDictEqual(vars(new_params), vars(second_params))
     self.assertNotEqual(vars(new_params), first_params_dict)
Beispiel #6
0
 def test_init_values_by_key(self):
     """Test that we can initialize values for new instances by name."""
     params = common.RetryParams(max_retries=1, initial_delay=2,
                                 max_backoff=3, backoff_factor=4,
                                 randomize=False)
     self.assertEqual(1, params.max_retries)
     self.assertEqual(2, params.initial_delay)
     self.assertEqual(3, params.max_backoff)
     self.assertEqual(4, params.backoff_factor)
     self.assertFalse(params.randomize)
Beispiel #7
0
 def test_retry_error_default_specify_both(self):
     """Test that we can set both arguments in the decorator."""
     function = mock.Mock(__name__='fake',
                          side_effect=gcs_errors.NotFound())
     retries = self.retries + 1
     slf = mock.Mock(spec=[])
     error_codes = [gcs_errors.NotFound.code]
     wrapper = common.retry(common.RetryParams(retries, 0), error_codes)
     wrapper = wrapper(function)
     self.assertRaises(gcs_errors.NotFound, wrapper, slf)
     # Initial call plus all the retries
     self.assertEqual(retries + 1, function.call_count)