Skip to content

Commit cadb4a4

Browse files
Fix tests
1 parent e255515 commit cadb4a4

3 files changed

Lines changed: 40 additions & 18 deletions

File tree

samples/inference-failover/create.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,8 +897,9 @@
897897
"metadata": {},
898898
"outputs": [],
899899
"source": [
900-
"from pathlib import Path\n",
900+
"import importlib\n",
901901
"import tempfile\n",
902+
"from pathlib import Path\n",
902903
"\n",
903904
"import matplotlib.pyplot as plt\n",
904905
"\n",
@@ -907,6 +908,8 @@
907908
"import htmlreport\n",
908909
"from console import print_ok, print_warning\n",
909910
"\n",
911+
"importlib.reload(htmlreport)\n",
912+
"\n",
910913
"if 'gpt_5_1_backend_labels' not in locals():\n",
911914
" print_warning('Please run the scenario chart cell first')\n",
912915
" raise SystemExit(1)\n",

tests/python/test_inference_failover.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,7 @@ def test_inference_notebook_generates_local_html_report() -> None:
336336
assert "'inference-failover-report.html'" in code_source
337337
assert "'', 'Test #', 'Scenario', 'Requests', 'HTTP 200', 'Other', 'APIM retries', 'Priority / weight mix', 'What the data says'" in code_source
338338
assert "htmlreport.HtmlText(f'Scenario Outcomes: {model_name}', bold_tokens=(model_name,))" in code_source
339-
assert 'if retry_count > 0' in code_source
340-
assert 'caller_succeeded = not non_200_responses' in code_source
341-
assert "htmlreport.HtmlSuccess('All requests returned HTTP 200')" in code_source
342-
assert "else htmlreport.HtmlWarning('Some requests returned non-200 responses')" in code_source
343-
assert "observation_items = tuple(f'{item.strip()}' for item in '; '.join(observations).split(';'))" in code_source
344-
assert 'htmlreport.HtmlList(observation_items)' in code_source
345-
assert 'htmlreport.HtmlText(retry_mix, preserve_line_breaks=True)' in code_source
346-
assert 'def get_priority_and_weight(' in code_source
347-
assert "weights_by_priority.setdefault(priority, []).append(f'W{weight}: {count} ({count / total_requests:.1%})')" in code_source
348-
assert "priority_mix = '\\n'.join(f'P{priority}: {\", \".join(weight_mix)}'" in code_source
349-
assert 'htmlreport.HtmlText(priority_mix, bold_tokens=priority_tokens, preserve_line_breaks=True)' in code_source
339+
assert 'inference_failover_helpers.build_scenario_report_row(' in code_source
350340
assert "column_widths=['4%', '5%', '10%', '6%', '6%', '5%', '11%', '17%', '36%']" in code_source
351341
assert "'A-1',\n 'Baseline Warm Path'" in code_source
352342
assert "'B-1',\n 'Baseline Warm Path'" in code_source
@@ -358,12 +348,6 @@ def test_inference_notebook_generates_local_html_report() -> None:
358348
assert 'report.add_info_callout(' in code_source
359349
assert "'Lab Capacity Is Intentionally Low'" in code_source
360350
assert "'Each regional Azure OpenAI deployment is intentionally configured at 1,000 TPM so that" in code_source
361-
assert 'observed_backend_failures = backend_retries_absorbed + caller_visible_failures' in code_source
362-
assert 'shielded_percentage = backend_retries_absorbed / observed_backend_failures * 100' in code_source
363-
assert "f'APIM absorbed {backend_retries_absorbed} backend failures and sent {caller_visible_failures} failures to callers'" in code_source
364-
assert "f'APIM prevented {shielded_percentage:.1f}% of observed failed backend attempts from reaching callers'" in code_source
365-
assert 'terminal_503_responses = status_counts.get(503, 0)' in code_source
366-
assert 'caller-visible HTTP 503 responses followed eligible-capacity exhaustion in the low-TPM pool' in code_source
367351
assert "'Observed X-Backend-URL values'" not in code_source.split('report = htmlreport.HtmlReport(', maxsplit=1)[1]
368352
assert 'if all_scenario_requests_succeeded:' in code_source
369353
assert 'report.add_success_callout(' in code_source

tests/python/test_inference_failover_helpers.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ def test_context_manager_closes_session_after_exception():
145145
session.close.assert_called_once_with()
146146

147147

148+
@pytest.mark.unit
149+
def test_close_is_idempotent_without_an_open_session():
150+
runner, session = _create_runner()
151+
152+
runner.close()
153+
runner.close()
154+
155+
session.close.assert_not_called()
156+
157+
148158
@pytest.mark.unit
149159
def test_pause_uses_injected_sleep_and_rejects_negative_values():
150160
sleep = MagicMock()
@@ -209,6 +219,18 @@ def test_with_backend_identifier_leaves_frames_without_urls_unchanged():
209219
assert result is not source
210220

211221

222+
@pytest.mark.unit
223+
def test_format_gateway_distribution_leaves_frames_without_backend_urls():
224+
source = pd.DataFrame([['api', 'not available', 'not available']], columns=['API', 'AverageBackendMs', 'SuccessRate'])
225+
226+
result = format_gateway_distribution(source)
227+
228+
assert result['AverageBackendMs'].tolist() == ['']
229+
assert result['SuccessRate'].tolist() == ['']
230+
assert 'Backend' not in result.columns
231+
assert result is not source
232+
233+
212234
@pytest.mark.unit
213235
def test_get_priority_and_weight_parses_legend_label():
214236
labels = {
@@ -273,3 +295,16 @@ def test_build_scenario_report_row_reports_failover_retries_and_terminal_503():
273295
assert 'no resolved backend' in observations
274296
assert 'HTTP 503 responses' in observations
275297
assert 'APIM prevented 80.0%' in observations
298+
299+
300+
@pytest.mark.unit
301+
def test_build_scenario_report_row_reports_unresolved_non_503_failure():
302+
results = [{'status_code': 429, 'backend_retry': 0, 'backend_url': 'unknown'}]
303+
304+
row = build_scenario_report_row('A-3', 'Capacity Exhausted', results, {}, {})
305+
306+
assert isinstance(row[0], HtmlWarning)
307+
assert row[7] == HtmlText('No resolved backend: 1 (100.0%)', preserve_line_breaks=True)
308+
observations = '\n'.join(row[8].items)
309+
assert 'caller-visible failures remained' in observations
310+
assert 'Deepest routed tier' not in observations

0 commit comments

Comments
 (0)