Example #1
0
    def test_jitter_has_randomness_but_within_range(self):
        client = new_default_http_client()

        jittered_ones = set(
            map(lambda _: client._add_jitter_time(1), list(range(100))))

        assert len(jittered_ones) > 1
        assert all(0.5 <= val <= 1 for val in jittered_ones)
Example #2
0
    def test_randomness_added(self):
        client = new_default_http_client()
        random_value = 0.8
        client._add_jitter_time = lambda t: t * random_value
        base_value = HTTPClient.INITIAL_DELAY * random_value

        with self.mock_max_delay(10):
            expected = [
                HTTPClient.INITIAL_DELAY, base_value * 2, base_value * 4,
                base_value * 8, base_value * 16
            ]
            self.assert_sleep_times(client, expected)
Example #3
0
    def __init__(self,
                 key=None,
                 client=None,
                 api_base=None,
                 api_version=None,
                 account=None):
        self.api_base = api_base or tap.api_base
        self.api_key = key
        self.api_version = api_version or tap.api_version
        self.tap_account = account

        from tap import verify_ssl_certs as verify
        from tap import proxy

        self._client = client or tap.default_http_client or \
            http_client.new_default_http_client(
                verify_ssl_certs=verify, proxy=proxy)
Example #4
0
 def test_maximum_delay(self):
     client = new_default_http_client()
     client._add_jitter_time = lambda t: t
     max_delay = HTTPClient.MAX_DELAY
     expected = [0.5, 1.0, max_delay, max_delay, max_delay]
     self.assert_sleep_times(client, expected)
Example #5
0
 def test_initial_delay_as_minimum(self):
     client = new_default_http_client()
     client._add_jitter_time = lambda t: t * 0.001
     initial_delay = HTTPClient.INITIAL_DELAY
     self.assert_sleep_times(client, [initial_delay] * 5)
Example #6
0
 def test_sleep_time_exponential_back_off(self):
     client = new_default_http_client()
     client._add_jitter_time = lambda t: t
     with self.mock_max_delay(10):
         self.assert_sleep_times(client, [0.5, 1.0, 2.0, 4.0, 8.0])