Ejemplo n.º 1
0
 def test_open(self, sleep):
     fn = Mock()
     connection = Mock(url=URL, retry=True)
     fx = retry(ConnectError)(fn)
     fx(connection)
     fn.assert_called_once_with(connection)
     self.assertFalse(sleep.called)
Ejemplo n.º 2
0
 def test_open(self, sleep):
     fn = Mock()
     connection = Mock(url=URL, retry=True)
     fx = retry(ConnectError)(fn)
     fx(connection)
     fn.assert_called_once_with(connection)
     self.assertFalse(sleep.called)
Ejemplo n.º 3
0
 def test_open_failed_no_retry(self, sleep):
     fn = Mock()
     fn.side_effect = [ConnectError]
     connection = Mock(url=URL, retry=False)
     fx = retry(ConnectError)(fn)
     self.assertRaises(ConnectError, fx, connection)
     self.assertFalse(sleep.called)
     fn.assert_called_once_with(connection)
Ejemplo n.º 4
0
 def test_open_failed_no_retry(self, sleep):
     fn = Mock()
     fn.side_effect = [ConnectError]
     connection = Mock(url=URL, retry=False)
     fx = retry(ConnectError)(fn)
     self.assertRaises(ConnectError, fx, connection)
     self.assertFalse(sleep.called)
     fn.assert_called_once_with(connection)
Ejemplo n.º 5
0
 def test_exceeded(self, sleep):
     fn = Mock()
     fn.side_effect = [ConnectError, ConnectError, ConnectError]
     connection = Mock(url=URL, retry=True)
     fx = retry(ConnectError)(fn)
     self.assertRaises(ConnectError, fx, connection)
     self.assertEqual(sleep.call_args_list, [
         ((DELAY, ), {}),
         ((DELAY * DELAY_MULTIPLIER, ), {}),
     ])
     self.assertEqual(fn.call_args_list, [
         ((connection, ), {}),
         ((connection, ), {}),
         ((connection, ), {}),
     ])
Ejemplo n.º 6
0
 def test_exceeded(self, sleep):
     fn = Mock()
     fn.side_effect = [ConnectError, ConnectError, ConnectError]
     connection = Mock(url=URL, retry=True)
     fx = retry(ConnectError)(fn)
     self.assertRaises(ConnectError, fx, connection)
     self.assertEqual(
         sleep.call_args_list,
         [
             ((DELAY,), {}),
             ((DELAY * DELAY_MULTIPLIER,), {}),
         ])
     self.assertEqual(
         fn.call_args_list,
         [
             ((connection,), {}),
             ((connection,), {}),
             ((connection,), {}),
         ])