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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from devtools_testutils import recorded_by_proxy
from preparers import app_config_decorator
from testcase import AppConfigTestCase
class TestAppConfigurationProvider(AppConfigTestCase):
# method: _calculate_backoff
@recorded_by_proxy
@app_config_decorator
def test_backoff(self, appconfiguration_connection_string, appconfiguration_keyvault_secret_url):
client = self.create_client(
appconfiguration_connection_string, keyvault_secret_url=appconfiguration_keyvault_secret_url
)
min_backoff = 30000
assert min_backoff == client._refresh_timer._calculate_backoff()
attempts = 2
client._refresh_timer.attempts = attempts
backoff = client._refresh_timer._calculate_backoff()
assert backoff >= min_backoff and backoff <= (min_backoff * (1 << attempts))
attempts = 3
client._refresh_timer.attempts = attempts
backoff = client._refresh_timer._calculate_backoff()
assert backoff >= min_backoff and backoff <= (min_backoff * (1 << attempts))
# method: _calculate_backoff
@recorded_by_proxy
@app_config_decorator
def test_backoff_max_attempts(self, appconfiguration_connection_string, appconfiguration_keyvault_secret_url):
client = self.create_client(
appconfiguration_connection_string,
keyvault_secret_url=appconfiguration_keyvault_secret_url,
)
min_backoff = 3000
# When attempts is > 30 then it acts as if it was 30
attempts = 30
client._refresh_timer.attempts = attempts
backoff = client._refresh_timer._calculate_backoff()
assert backoff >= min_backoff and backoff <= (min_backoff * (1 << attempts))
attempts = 31
client._refresh_timer.attempts = attempts
backoff = client._refresh_timer._calculate_backoff()
assert backoff >= min_backoff and backoff <= (min_backoff * (1 << 30))
# method: _calculate_backoff
@recorded_by_proxy
@app_config_decorator
def test_backoff_bounds(self, appconfiguration_connection_string, appconfiguration_keyvault_secret_url):
client = self.create_client(
appconfiguration_connection_string,
keyvault_secret_url=appconfiguration_keyvault_secret_url,
refresh_interval=1,
)
assert client._refresh_timer._min_backoff == 1
assert client._refresh_timer._max_backoff == 1
client = self.create_client(
appconfiguration_connection_string,
keyvault_secret_url=appconfiguration_keyvault_secret_url,
refresh_interval=45,
)
assert client._refresh_timer._min_backoff == 30
assert client._refresh_timer._max_backoff == 45
client = self.create_client(
appconfiguration_connection_string,
keyvault_secret_url=appconfiguration_keyvault_secret_url,
refresh_interval=700,
)
assert client._refresh_timer._min_backoff == 30
assert client._refresh_timer._max_backoff == 600
# method: _calculate_backoff
@recorded_by_proxy
@app_config_decorator
def test_backoff_invalid_attempts(self, appconfiguration_connection_string, appconfiguration_keyvault_secret_url):
client = self.create_client(
appconfiguration_connection_string, keyvault_secret_url=appconfiguration_keyvault_secret_url
)
min_backoff = 30000 # 30 Seconds in milliseconds
# When attempts is < 1 then it acts as if it was 1
attempts = 0
client._refresh_timer.attempts = attempts
backoff = client._refresh_timer._calculate_backoff()
assert backoff == min_backoff
attempts = -1
client._refresh_timer.attempts = attempts
backoff = client._refresh_timer._calculate_backoff()
assert backoff == min_backoff
# method: _calculate_backoff
@recorded_by_proxy
@app_config_decorator
def test_backoff_missmatch_settings(self, appconfiguration_connection_string, appconfiguration_keyvault_secret_url):
min_backoff = 30000
client = self.create_client(
appconfiguration_connection_string, keyvault_secret_url=appconfiguration_keyvault_secret_url
)
# When attempts is < 1 then it acts as if it was 1
client._refresh_timer.attempts = 0
backoff = client._refresh_timer._calculate_backoff()
assert backoff == min_backoff
|