Skip to content

Commit 5dcecd1

Browse files
committed
test: fix TestGetLlmTee to patch random.choice for deterministic CI
1 parent deff27c commit 5dcecd1

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

tests/tee_registry_test.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import ssl
33
import sys
4+
import random
45
from unittest.mock import MagicMock, patch
56

67
import pytest
@@ -148,19 +149,36 @@ def test_validator_type_label(self, mock_contract):
148149

149150

150151
class TestGetLlmTee:
151-
def test_returns_first_active_tee(self, mock_contract):
152+
def test_returns_active_tee_from_pool(self, mock_contract):
153+
"""get_llm_tee uses random.choice; patch it to make the test deterministic."""
152154
registry, contract = mock_contract
153155

154-
contract.functions.getActiveTEEs.return_value.call.return_value = [
156+
tee_infos = [
155157
_make_tee_info(endpoint="https://tee-1.example.com"),
156158
_make_tee_info(endpoint="https://tee-2.example.com"),
157159
]
160+
contract.functions.getActiveTEEs.return_value.call.return_value = tee_infos
158161

159-
result = registry.get_llm_tee()
162+
with patch("src.opengradient.client.tee_registry.random.choice", side_effect=lambda seq: seq[0]):
163+
result = registry.get_llm_tee()
160164

161165
assert result is not None
162166
assert result.endpoint == "https://tee-1.example.com"
163167

168+
def test_returns_any_active_tee(self, mock_contract):
169+
"""Without patching random.choice, result must still be one of the active TEEs."""
170+
registry, contract = mock_contract
171+
172+
endpoints = {"https://tee-1.example.com", "https://tee-2.example.com"}
173+
contract.functions.getActiveTEEs.return_value.call.return_value = [
174+
_make_tee_info(endpoint=ep) for ep in sorted(endpoints)
175+
]
176+
177+
result = registry.get_llm_tee()
178+
179+
assert result is not None
180+
assert result.endpoint in endpoints
181+
164182
def test_returns_none_when_no_tees(self, mock_contract):
165183
registry, contract = mock_contract
166184

0 commit comments

Comments
 (0)