Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppConfig] Fix flaky tests #30577

Merged
merged 3 commits into from
Jun 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion sdk/appconfiguration/azure-appconfiguration/assets.json
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",
"Tag": "python/appconfiguration/azure-appconfiguration_ab4d812492"
"Tag": "python/appconfiguration/azure-appconfiguration_bbc12a70b5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def list_configuration_settings(
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword datetime accept_datetime: retrieve ConfigurationSetting existed at this datetime
:keyword List[str] fields: specify which fields to include in the results. Leave None to include all fields
:return: An iterator of :class:`ConfigurationSetting`
:rtype: ~azure.core.paging.ItemPaged[ConfigurationSetting]
Expand All @@ -165,7 +165,7 @@ def list_configuration_settings(

from datetime import datetime, timedelta

accept_datetime = datetime.today() + timedelta(days=-1)
accept_datetime = datetime.utcnow() + timedelta(days=-1)

all_listed = client.list_configuration_settings()
for item in all_listed:
Expand Down Expand Up @@ -216,7 +216,7 @@ def get_configuration_setting(
:type etag: str or None
:param match_condition: The match condition to use upon the etag
:type match_condition: :class:`~azure.core.MatchConditions`
:keyword datetime accept_datetime: the retrieved ConfigurationSetting that created no later than this datetime
:keyword datetime accept_datetime: retrieve ConfigurationSetting existed at this datetime
:return: The matched ConfigurationSetting object
:rtype: :class:`~azure.appconfiguration.ConfigurationSetting`
:raises: :class:`HttpResponseError`, :class:`ClientAuthenticationError`, \
Expand Down Expand Up @@ -431,7 +431,7 @@ def list_revisions(
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword datetime accept_datetime: retrieve ConfigurationSetting existed at this datetime
:keyword List[str] fields: specify which fields to include in the results. Leave None to include all fields
:return: An iterator of :class:`ConfigurationSetting`
:rtype: ~azure.core.paging.ItemPaged[ConfigurationSetting]
Expand All @@ -443,7 +443,7 @@ def list_revisions(

from datetime import datetime, timedelta

accept_datetime = datetime.today() + timedelta(days=-1)
accept_datetime = datetime.utcnow() + timedelta(days=-1)

all_revisions = client.list_revisions()
for item in all_revisions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def list_configuration_settings(
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword datetime accept_datetime: retrieve ConfigurationSetting existed at this datetime
:keyword List[str] fields: specify which fields to include in the results. Leave None to include all fields
:return: An iterator of :class:`ConfigurationSetting`
:rtype: ~azure.core.async_paging.AsyncItemPaged[ConfigurationSetting]
Expand All @@ -146,7 +146,7 @@ def list_configuration_settings(

from datetime import datetime, timedelta

accept_datetime = datetime.today() + timedelta(days=-1)
accept_datetime = datetime.utcnow() + timedelta(days=-1)

all_listed = async_client.list_configuration_settings()
async for item in all_listed:
Expand Down Expand Up @@ -198,7 +198,7 @@ async def get_configuration_setting(
:type etag: str or None
:param match_condition: The match condition to use upon the etag
:type match_condition: :class:`~azure.core.MatchConditions`
:keyword datetime accept_datetime: the retrieved ConfigurationSetting that created no later than this datetime
:keyword datetime accept_datetime: retrieve ConfigurationSetting existed at this datetime
:return: The matched ConfigurationSetting object
:rtype: :class:`~azure.appconfiguration.ConfigurationSetting`
:raises: :class:`HttpResponseError`, :class:`ClientAuthenticationError`, \
Expand Down Expand Up @@ -427,7 +427,7 @@ def list_revisions(
:param label_filter: filter results based on their label. '*' can be
used as wildcard in the beginning or end of the filter
:type label_filter: str
:keyword datetime accept_datetime: filter out ConfigurationSetting created after this datetime
:keyword datetime accept_datetime: retrieve ConfigurationSetting existed at this datetime
:keyword List[str] fields: specify which fields to include in the results. Leave None to include all fields
:return: An iterator of :class:`ConfigurationSetting`
:rtype: ~azure.core.async_paging.AsyncItemPaged[ConfigurationSetting]
Expand All @@ -440,7 +440,7 @@ def list_revisions(
# in async function
from datetime import datetime, timedelta

accept_datetime = datetime.today() + timedelta(days=-1)
accept_datetime = datetime.utcnow() + timedelta(days=-1)

all_revisions = async_client.list_revisions()
async for item in all_revisions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# --------------------------------------------------------------------------
from azure.appconfiguration.aio import AzureAppConfigurationClient
from azure.core.async_paging import AsyncItemPaged
from azure.core.exceptions import ResourceExistsError
from testcase import AppConfigTestCase
from typing import List

Expand All @@ -19,13 +20,10 @@ def create_client(self, appconfiguration_connection_string):
return AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string)

async def add_for_test(self, client, config_setting):
exist_list = await self.convert_to_list(
client.list_configuration_settings(key_filter=config_setting.key, label_filter=config_setting.label)
)
exist = bool(exist_list)
if exist:
await client.delete_configuration_setting(key=config_setting.key, label=config_setting.label)
return await client.add_configuration_setting(config_setting)
try:
await client.add_configuration_setting(config_setting)
except ResourceExistsError:
pass

async def convert_to_list(self, config_settings: AsyncItemPaged) -> List:
list = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_list_configuration_settings_contains(self, appconfiguration_connection_
def test_list_configuration_settings_correct_etag(self, appconfiguration_connection_string):
client = self.create_client(appconfiguration_connection_string)
to_list_kv = self.create_config_setting()
to_list_kv = self.add_for_test(client, to_list_kv)
self.add_for_test(client, to_list_kv)
custom_headers = {"If-Match": to_list_kv.etag}
items = list(
client.list_configuration_settings(
Expand Down Expand Up @@ -361,15 +361,16 @@ def test_list_configuration_settings_no_label(self, appconfiguration_connection_
@recorded_by_proxy
def test_list_configuration_settings_only_accepttime(self, appconfiguration_connection_string, **kwargs):
recorded_variables = kwargs.pop("variables", {})
self.set_up(appconfiguration_connection_string)
exclude_today = self.client.list_configuration_settings(
accept_datetime=recorded_variables.setdefault(
"datetime", str(datetime.datetime.today() + datetime.timedelta(days=-1))
)
)
all_inclusive = self.client.list_configuration_settings()
assert len(list(all_inclusive)) > len(list(exclude_today))
self.tear_down()
recorded_variables.setdefault("timestamp", str(datetime.datetime.utcnow()))

with AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string) as client:
# Confirm all configuration settings are cleaned up
current_config_settings = client.list_configuration_settings()
assert len(list(current_config_settings)) == 0

revision = client.list_configuration_settings(accept_datetime=recorded_variables.get("timestamp"))
assert len(list(revision)) >= 0

return recorded_variables

# method: list_revisions
Expand Down Expand Up @@ -414,7 +415,7 @@ def test_list_revisions_fields(self, appconfiguration_connection_string):
def test_list_revisions_correct_etag(self, appconfiguration_connection_string):
client = self.create_client(appconfiguration_connection_string)
to_list_kv = self.create_config_setting()
to_list_kv = self.add_for_test(client, to_list_kv)
self.add_for_test(client, to_list_kv)
custom_headers = {"If-Match": to_list_kv.etag}
items = list(
client.list_revisions(key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def test_list_configuration_settings_contains(self, appconfiguration_endpoint_st
def test_list_configuration_settings_correct_etag(self, appconfiguration_endpoint_string):
client = self.create_aad_client(appconfiguration_endpoint_string)
to_list_kv = self.create_config_setting()
to_list_kv = self.add_for_test(client, to_list_kv)
self.add_for_test(client, to_list_kv)
custom_headers = {"If-Match": to_list_kv.etag}
items = list(
client.list_configuration_settings(
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_list_revisions_fields(self, appconfiguration_endpoint_string):
def test_list_revisions_correct_etag(self, appconfiguration_endpoint_string):
client = self.create_aad_client(appconfiguration_endpoint_string)
to_list_kv = self.create_config_setting()
to_list_kv = self.add_for_test(client, to_list_kv)
self.add_for_test(client, to_list_kv)
custom_headers = {"If-Match": to_list_kv.etag}
items = list(
client.list_revisions(key_filter=to_list_kv.key, label_filter=to_list_kv.label, headers=custom_headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import datetime
import json
import re
import copy
from azure.core import MatchConditions
from azure.core.exceptions import (
ResourceModifiedError,
Expand Down Expand Up @@ -365,17 +364,18 @@ async def test_list_configuration_settings_no_label(self, appconfiguration_conne
@recorded_by_proxy_async
async def test_list_configuration_settings_only_accepttime(self, appconfiguration_connection_string, **kwargs):
recorded_variables = kwargs.pop("variables", {})
await self.set_up(appconfiguration_connection_string)
exclude_today = await self.convert_to_list(
self.client.list_configuration_settings(
accept_datetime=recorded_variables.setdefault(
"datetime", str(datetime.datetime.today() + datetime.timedelta(days=-1))
)
recorded_variables.setdefault("timestamp", str(datetime.datetime.utcnow()))

async with AzureAppConfigurationClient.from_connection_string(appconfiguration_connection_string) as client:
# Confirm all configuration settings are cleaned up
current_config_settings = await self.convert_to_list(client.list_configuration_settings())
assert len(current_config_settings) == 0

revision = await self.convert_to_list(
client.list_configuration_settings(accept_datetime=recorded_variables.get("timestamp"))
)
)
all_inclusive = await self.convert_to_list(self.client.list_configuration_settings())
assert len(all_inclusive) > len(exclude_today)
await self.tear_down()
assert len(revision) >= 0

return recorded_variables

# method: list_revisions
Expand Down
11 changes: 5 additions & 6 deletions sdk/appconfiguration/azure-appconfiguration/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FeatureFlagConfigurationSetting,
SecretReferenceConfigurationSetting,
)
from azure.core.exceptions import ResourceExistsError
from consts import (
KEY,
LABEL,
Expand Down Expand Up @@ -46,12 +47,10 @@ def create_config_setting_no_label(self):
)

def add_for_test(self, client, config_setting):
key = config_setting.key
label = config_setting.label
exist = bool(list(client.list_configuration_settings(key_filter=key, label_filter=label)))
if exist:
client.delete_configuration_setting(key=config_setting.key, label=config_setting.label)
return client.add_configuration_setting(config_setting)
try:
client.add_configuration_setting(config_setting)
except ResourceExistsError:
pass

def set_up(self, appconfiguration_string, is_aad=False):
if is_aad:
Expand Down