1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
from tests import unittest
from botocore.retries import quota
class TestRetryQuota(unittest.TestCase):
def setUp(self):
self.retry_quota = quota.RetryQuota(50)
def test_can_acquire_amount(self):
self.assertTrue(self.retry_quota.acquire(5))
self.assertEqual(self.retry_quota.available_capacity, 45)
def test_can_release_amount(self):
self.assertTrue(self.retry_quota.acquire(5))
self.assertEqual(self.retry_quota.available_capacity, 45)
self.retry_quota.release(5)
self.assertEqual(self.retry_quota.available_capacity, 50)
def test_cant_exceed_max_capacity(self):
self.assertTrue(self.retry_quota.acquire(5))
self.assertEqual(self.retry_quota.available_capacity, 45)
self.retry_quota.release(10)
self.assertEqual(self.retry_quota.available_capacity, 50)
def test_noop_if_at_max_capacity(self):
self.retry_quota.release(10)
self.assertEqual(self.retry_quota.available_capacity, 50)
def test_cant_go_below_zero(self):
self.assertTrue(self.retry_quota.acquire(49))
self.assertEqual(self.retry_quota.available_capacity, 1)
self.assertFalse(self.retry_quota.acquire(10))
self.assertEqual(self.retry_quota.available_capacity, 1)
|