Skip to content

Commit fb95607

Browse files
Merge branch 'main' into feature/storage-stg101
2 parents 2ca3246 + 66b3282 commit fb95607

File tree

16 files changed

+533
-84
lines changed

16 files changed

+533
-84
lines changed

doc/dev/test_proxy_troubleshooting.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ To run recorded tests successfully when recorded values are inconsistent or rand
275275
proxy provides a `variables` API. This makes it possible for a test to record the values of variables that were used
276276
during recording and use the same values in playback mode without a sanitizer.
277277

278+
Note that the recorded variables **must** have string values. For example, trying to record an integer value for a
279+
variable will cause a test proxy error.
280+
278281
For example, imagine that a test uses a randomized `table_uuid` variable when creating resources. The same random value
279282
for `table_uuid` can be used in playback mode by using this `variables` API.
280283

@@ -293,14 +296,14 @@ class TestExample(AzureRecordedTestCase):
293296
@recorded_by_proxy
294297
def test_example(self, **kwargs):
295298
# In live mode, variables is an empty dictionary
296-
# In playback mode, the value of variables is {"table_uuid": "random-value"}
299+
# In playback mode, the value of variables is {"current_time": "<previously recorded time>"}
297300
variables = kwargs.pop("variables", {})
298301

299-
# To fetch variable values, use the `setdefault` method to look for a key ("table_uuid")
300-
# and set a real value for that key if it's not present ("random-value")
301-
table_uuid = variables.setdefault("table_uuid", "random-value")
302+
# To fetch variable values, use the `setdefault` method to look for a key ("current_time")
303+
# and set a real value for that key if it's not present (str(time.time()))
304+
# Note that time.time() is converted from a float to a string to record it properly
305+
current_time = variables.setdefault("current_time", str(time.time()))
302306

303-
# use variables["table_uuid"] when using the table UUID throughout the test
304307
...
305308

306309
# return the variables at the end of the test to record them

eng/pipelines/templates/steps/build-package-artifacts.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ steps:
109109
condition: and(succeeded(), or(eq(variables['ENABLE_EXTENSION_BUILD'], 'true'), eq('${{ parameters.ArtifactSuffix }}', 'linux')))
110110
111111
- script: |
112+
sudo dpkg --configure -a
112113
sudo apt-get update
113114
sudo apt-get install -y qemu-user-static binfmt-support
114115
sudo update-binfmts --enable qemu-aarch64

eng/pipelines/templates/steps/install-portaudio.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
steps:
22
- script: |
33
if [[ "$AGENT_OS" == "Linux" ]]; then
4+
sudo dpkg --configure -a
45
sudo apt-get update
56
sudo apt-get install -y portaudio19-dev libasound2-dev
67
elif [[ "$AGENT_OS" == "Darwin" ]]; then

eng/tools/azure-sdk-tools/devtools_testutils/proxy_testcase.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,32 +114,31 @@ def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
114114

115115

116116
def stop_record_or_playback(test_id: str, recording_id: str, test_variables: "Dict[str, str]") -> None:
117-
try:
118-
http_client = get_http_client()
119-
if is_live():
120-
http_client.request(
121-
method="POST",
122-
url=RECORDING_STOP_URL,
123-
headers={
124-
"x-recording-file": test_id,
125-
"x-recording-id": recording_id,
126-
"x-recording-save": "true",
127-
"Content-Type": "application/json",
128-
},
129-
# tests don't record successfully unless test_variables is a dictionary
130-
body=json.dumps(test_variables).encode("utf-8") if test_variables else "{}",
131-
)
132-
else:
133-
http_client.request(
134-
method="POST",
135-
url=PLAYBACK_STOP_URL,
136-
headers={"x-recording-id": recording_id},
137-
)
138-
except HTTPError as e:
117+
http_client = get_http_client()
118+
if is_live():
119+
response = http_client.request(
120+
method="POST",
121+
url=RECORDING_STOP_URL,
122+
headers={
123+
"x-recording-file": test_id,
124+
"x-recording-id": recording_id,
125+
"x-recording-save": "true",
126+
"Content-Type": "application/json",
127+
},
128+
# tests don't record successfully unless test_variables is a dictionary
129+
body=json.dumps(test_variables or {}).encode("utf-8"),
130+
)
131+
else:
132+
response = http_client.request(
133+
method="POST",
134+
url=PLAYBACK_STOP_URL,
135+
headers={"x-recording-id": recording_id},
136+
)
137+
if response.status >= 400:
139138
raise HttpResponseError(
140139
"The test proxy ran into an error while ending the session. Make sure any test variables you record have "
141-
"string values."
142-
) from e
140+
f"string values. Full error details: {response.data}"
141+
)
143142

144143

145144
def get_proxy_netloc() -> "Dict[str, str]":

sdk/communication/azure-communication-callautomation/tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# --------------------------------------------------------------------------
6+
import sys
67
import pytest
78
import os
89
import asyncio
@@ -14,15 +15,21 @@
1415
add_body_key_sanitizer,
1516
add_general_string_sanitizer,
1617
remove_batch_sanitizers,
18+
set_custom_default_matcher
1719
)
1820

1921

2022
# autouse=True will trigger this fixture on each pytest run, even if it's not explicitly used by a test method
2123
@pytest.fixture(scope="session", autouse=True)
2224
def start_proxy(test_proxy):
23-
2425
set_default_session_settings()
2526

27+
# On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
28+
# By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
29+
if sys.version_info >= (3, 14):
30+
headers_to_ignore = "Accept-Encoding"
31+
set_custom_default_matcher(ignored_headers=headers_to_ignore)
32+
2633
fake_connection_str = "endpoint=https://sanitized.communication.azure.com/;accesskey=fake=="
2734
connection_str = os.getenv("COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING", fake_connection_str)
2835
add_general_string_sanitizer(target=connection_str, value=fake_connection_str)

sdk/communication/azure-communication-identity/tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
# cSpell:ignore ests
2828
import pytest
2929
import os
30+
import sys
3031
from devtools_testutils import (
32+
set_custom_default_matcher,
3133
test_proxy,
3234
add_general_regex_sanitizer,
3335
add_header_regex_sanitizer,
@@ -42,6 +44,13 @@
4244
@pytest.fixture(scope="session", autouse=True)
4345
def add_sanitizers(test_proxy):
4446
set_default_session_settings()
47+
48+
# On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
49+
# By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
50+
if sys.version_info >= (3, 14):
51+
headers_to_ignore = "Accept-Encoding"
52+
set_custom_default_matcher(ignored_headers=headers_to_ignore)
53+
4554
add_oauth_response_sanitizer()
4655

4756
connection_str = os.environ.get("COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING")

sdk/communication/azure-communication-jobrouter/tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
add_uri_regex_sanitizer,
3737
add_body_key_sanitizer,
3838
remove_batch_sanitizers,
39+
set_custom_default_matcher
3940
)
4041
from router_test_constants import SANITIZED, FAKE_FUNCTION_URI, FAKE_ENDPOINT, FAKE_CONNECTION_STRING
4142
from azure.communication.jobrouter._shared.utils import parse_connection_str
@@ -49,6 +50,12 @@
4950
def start_proxy(test_proxy):
5051
set_default_session_settings()
5152

53+
# On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
54+
# By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
55+
if sys.version_info >= (3, 14):
56+
headers_to_ignore = "Accept-Encoding"
57+
set_custom_default_matcher(ignored_headers=headers_to_ignore)
58+
5259
communication_connection_string = os.getenv(
5360
"COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING", FAKE_CONNECTION_STRING
5461
)

sdk/communication/azure-communication-messages/tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
# cSpell:ignore ests
2828
import pytest
2929
import os
30+
import sys
3031
from devtools_testutils import (
32+
set_custom_default_matcher,
3133
test_proxy,
3234
add_header_regex_sanitizer,
3335
set_default_session_settings,
@@ -43,6 +45,13 @@
4345
@pytest.fixture(scope="session", autouse=True)
4446
def start_proxy(test_proxy):
4547
set_default_session_settings()
48+
49+
# On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
50+
# By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
51+
if sys.version_info >= (3, 14):
52+
headers_to_ignore = "Accept-Encoding"
53+
set_custom_default_matcher(ignored_headers=headers_to_ignore)
54+
4655
add_oauth_response_sanitizer()
4756

4857
FAKE_CONNECTION_STRING = "endpoint=https://sanitized.unitedstates.ppe.communication.azure.net/;accesskey=fake==="

sdk/communication/azure-communication-rooms/tests/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
# --------------------------------------------------------------------------
2626
import pytest
2727
import os
28+
import sys
2829
from devtools_testutils import (
2930
add_general_string_sanitizer,
3031
add_header_regex_sanitizer,
3132
set_default_session_settings,
3233
remove_batch_sanitizers,
3334
add_uri_regex_sanitizer,
35+
set_custom_default_matcher
3436
)
3537
from azure.communication.rooms._shared.utils import parse_connection_str
3638

@@ -39,6 +41,12 @@
3941
def add_sanitizers(test_proxy):
4042
set_default_session_settings()
4143

44+
# On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
45+
# By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
46+
if sys.version_info >= (3, 14):
47+
headers_to_ignore = "Accept-Encoding"
48+
set_custom_default_matcher(ignored_headers=headers_to_ignore)
49+
4250
communication_connection_string = os.getenv(
4351
"COMMUNICATION_CONNECTION_STRING_ROOMS", "endpoint=https://sanitized.communication.azure.com/;accesskey=fake==="
4452
)

sdk/communication/azure-communication-sms/tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,29 @@
2727
# cSpell:ignore ests
2828
import pytest
2929
import os
30+
import sys
3031
from devtools_testutils import (
3132
test_proxy,
3233
add_header_regex_sanitizer,
3334
set_default_session_settings,
3435
add_body_key_sanitizer,
3536
add_oauth_response_sanitizer,
3637
add_general_string_sanitizer,
38+
set_custom_default_matcher
3739
)
3840
from azure.communication.sms._shared.utils import parse_connection_str
3941

4042

4143
@pytest.fixture(scope="session", autouse=True)
4244
def add_sanitizers(test_proxy):
4345
set_default_session_settings()
46+
47+
# On python 3.14, azure-core sends an additional 'Accept-Encoding' header value that causes playback issues.
48+
# By ignoring it, we can avoid really wonky mismatch errors, while still validating the other headers
49+
if sys.version_info >= (3, 14):
50+
headers_to_ignore = "Accept-Encoding"
51+
set_custom_default_matcher(ignored_headers=headers_to_ignore)
52+
4453
add_oauth_response_sanitizer()
4554

4655
connection_str = os.environ.get("COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING")

0 commit comments

Comments
 (0)