Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/appconfiguration/azure-appconfiguration-provider",
"Tag": "python/appconfiguration/azure-appconfiguration-provider_ec20db0e42"
"Tag": "python/appconfiguration/azure-appconfiguration-provider_d81e6a8e3c"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# --------------------------------------------------------------------------
import functools
import time
import asyncio
import unittest
from unittest.mock import Mock, patch
from devtools_testutils import EnvironmentVariableLoader
Expand Down Expand Up @@ -63,16 +62,11 @@ async def async_callback():

# Mock the refresh method to track calls
with patch.object(client, "refresh") as mock_refresh:
# Wait for the secret refresh interval to pass
await asyncio.sleep(2)

await client.refresh()

# Verify refresh was called
assert mock_refresh.call_count >= 1

# Wait again to ensure multiple refreshes
await asyncio.sleep(2)
await client.refresh()

# Should have been called at least twice now
Expand Down Expand Up @@ -116,15 +110,20 @@ async def test_secret_refresh_with_updated_values(
kv_setting.secret_id = appconfiguration_keyvault_secret_url2
await appconfig_client.set_configuration_setting(kv_setting)

# Wait for the secret refresh interval to pass
await asyncio.sleep(2)
try:
# Expire the refresh timers to simulate time passing
client._refresh_timer._next_refresh_time = 0
client._secret_provider.secret_refresh_timer._next_refresh_time = 0

# Access the value again to trigger refresh
await client.refresh()
# Access the value again to trigger refresh
await client.refresh()

# Verify the value was updated
assert client["secret"] == "Very secret value 2"
assert mock_callback.call_count >= 1
# Verify the value was updated
assert client["secret"] == "Very secret value 2"
assert mock_callback.call_count >= 1
finally:
kv_setting.secret_id = appconfiguration_keyvault_secret_url
await appconfig_client.set_configuration_setting(kv_setting)

@AppConfigProviderPreparer()
@recorded_by_proxy_async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from devtools_testutils import EnvironmentVariableLoader
from devtools_testutils.aio import recorded_by_proxy_async
from testcase import has_feature_flag
from asynctestcase import AppConfigTestCase, setup_configs
from asynctestcase import AppConfigTestCase
from test_constants import APPCONFIGURATION_ENDPOINT_STRING, FEATURE_MANAGEMENT_KEY
from azure.appconfiguration.provider import SettingSelector
from azure.appconfiguration.provider.aio import load
Expand Down Expand Up @@ -38,9 +38,6 @@ async def test_load_only_feature_flags(self, appconfiguration_endpoint_string):
@AppConfigProviderPreparer()
@recorded_by_proxy_async
async def test_select_feature_flags(self, appconfiguration_endpoint_string):
client = self.create_appconfig_client(appconfiguration_endpoint_string)
await setup_configs(client, None, None)

credential = self.get_credential(AzureAppConfigurationClient, is_async=True)
async with await load(
endpoint=appconfiguration_endpoint_string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# license information.
# --------------------------------------------------------------------------
import functools
import time
import unittest
import sys
from unittest.mock import Mock
Expand Down Expand Up @@ -63,8 +62,9 @@ async def test_refresh(self, appconfiguration_endpoint_string, appconfiguration_
await appconfig_client.set_configuration_setting(setting)
await appconfig_client.set_configuration_setting(feature_flag)

# Waiting for the refresh interval to pass
time.sleep(2)
# Expire the refresh timers to simulate time passing
client._refresh_timer._next_refresh_time = 0
client._feature_flag_refresh_timer._next_refresh_time = 0

await client.refresh()
assert client["refresh_message"] == "updated value"
Expand All @@ -76,8 +76,9 @@ async def test_refresh(self, appconfiguration_endpoint_string, appconfiguration_
await appconfig_client.set_configuration_setting(setting)
await appconfig_client.set_configuration_setting(feature_flag)

# Waiting for the refresh interval to pass
time.sleep(2)
# Expire the refresh timers to simulate time passing
client._refresh_timer._next_refresh_time = 0
client._feature_flag_refresh_timer._next_refresh_time = 0

await client.refresh()
assert client["refresh_message"] == "original value"
Expand All @@ -96,7 +97,9 @@ async def test_refresh(self, appconfiguration_endpoint_string, appconfiguration_
assert mock_callback.call_count == 2

setting.value = "original value"
feature_flag.enabled = False
await appconfig_client.set_configuration_setting(setting)
await appconfig_client.set_configuration_setting(feature_flag)

await client.refresh()
assert client["refresh_message"] == "original value"
Expand Down Expand Up @@ -133,8 +136,9 @@ async def test_no_refresh(self, appconfiguration_endpoint_string, appconfigurati
setting.value = "updated value"
await appconfig_client.set_configuration_setting(setting)

# Waiting for the refresh interval to pass
time.sleep(2)
# Expire the refresh timers to simulate time passing
client._refresh_timer._next_refresh_time = 0
client._feature_flag_refresh_timer._next_refresh_time = 0

await client.refresh()
# No Change the Watch Key wasn't updated
Expand All @@ -145,15 +149,20 @@ async def test_no_refresh(self, appconfiguration_endpoint_string, appconfigurati
watch_key.value = "1"
await appconfig_client.set_configuration_setting(watch_key)

# Waiting for the refresh interval to pass
time.sleep(2)
# Expire the refresh timers to simulate time passing
client._refresh_timer._next_refresh_time = 0
client._feature_flag_refresh_timer._next_refresh_time = 0

await client.refresh()
assert client["refresh_message"] == "updated value"
assert has_feature_flag(client, "Alpha", False)
assert mock_callback.call_count == 1

# method: refresh
# Reset modified settings
setting.value = "original value"
await appconfig_client.set_configuration_setting(setting)
await appconfig_client.delete_configuration_setting(key="watch key")

@AppConfigProviderPreparer()
@recorded_by_proxy_async
@pytest.mark.skipif(sys.version_info < (3, 8), reason="Python 3.7 does not support AsyncMock")
Expand Down Expand Up @@ -181,8 +190,8 @@ async def test_empty_refresh(self, appconfiguration_endpoint_string, appconfigur
static_setting.value = "updated static"
await appconfig_client.set_configuration_setting(static_setting)

# Waiting for the refresh interval to pass
time.sleep(2)
# Expire the refresh timers to simulate time passing
client._refresh_timer._next_refresh_time = 0

await client.refresh()
assert client["refresh_message"] == "original value"
Expand Down
Loading
Loading