File: test_quota.py

package info (click to toggle)
python-botocore 1.20.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 60,608 kB
  • sloc: python: 50,632; xml: 15,052; makefile: 131
file content (35 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (4)
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)