Skip to content

Commit b78a670

Browse files
authored
[Monitor Query] Fix server timeout live tests (#36916)
Signed-off-by: Paul Van Eck <[email protected]>
1 parent 494b19b commit b78a670

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

sdk/monitor/azure-monitor-query/tests/test_logs_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,21 @@ def test_logs_single_query_with_partial_success(self, recorded_test, monitor_inf
7373
def test_logs_server_timeout(self, recorded_test, monitor_info):
7474
client = self.get_client(LogsQueryClient, self.get_credential(LogsQueryClient))
7575

76-
with pytest.raises(HttpResponseError) as e:
76+
try:
7777
response = client.query_workspace(
78-
monitor_info['workspace_id'],
78+
monitor_info["workspace_id"],
7979
"range x from 1 to 1000000000000000 step 1 | count",
8080
timespan=None,
8181
server_timeout=2,
82-
retry_total=0
82+
retry_total=0,
8383
)
84-
assert 'Gateway timeout' in e.value.message
84+
except HttpResponseError as e:
85+
assert "Gateway timeout" in e.message
86+
else:
87+
# Response an be observed as either 504 response code from the gateway or a partial failure 200 response.
88+
assert response.status == LogsQueryStatus.PARTIAL
89+
assert "timed out" in str(response.partial_error)
90+
8591

8692
@pytest.mark.live_test_only("Issues recording dynamic 'id' values in requests/responses")
8793
def test_logs_query_batch_default(self, monitor_info):

sdk/monitor/azure-monitor-query/tests/test_logs_client_async.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,23 @@ async def test_logs_auth_no_timespan(self, monitor_info):
4747

4848
@pytest.mark.asyncio
4949
async def test_logs_server_timeout(self, recorded_test, monitor_info):
50-
client = self.get_client(
51-
LogsQueryClient, self.get_credential(LogsQueryClient, is_async=True))
50+
client = self.get_client(LogsQueryClient, self.get_credential(LogsQueryClient, is_async=True))
5251

53-
with pytest.raises(HttpResponseError) as e:
52+
try:
5453
async with client:
55-
await client.query_workspace(
56-
monitor_info['workspace_id'],
54+
response = await client.query_workspace(
55+
monitor_info["workspace_id"],
5756
"range x from 1 to 1000000000000000 step 1 | count",
5857
timespan=None,
5958
server_timeout=2,
6059
retry_total=0,
6160
)
62-
63-
assert 'Gateway timeout' in e.value.message
61+
except HttpResponseError as e:
62+
assert "Gateway timeout" in e.message
63+
else:
64+
# Response an be observed as either 504 response code from the gateway or a partial failure 200 response.
65+
assert response.status == LogsQueryStatus.PARTIAL
66+
assert "timed out" in str(response.partial_error)
6467

6568
@pytest.mark.asyncio
6669
async def test_logs_query_batch_raises_on_no_timespan(self, monitor_info):

0 commit comments

Comments
 (0)