Skip to content

Commit 243a130

Browse files
committed
Fix test failures from credential encryption and async test changes
1 parent ef6e911 commit 243a130

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

tests/test_cli_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ def test_save_credentials_writes_file(self):
260260
assert creds_file.exists()
261261
with open(creds_file, "r") as f:
262262
loaded = json.load(f)
263-
assert loaded == {"runpod": {"api_key": "test_key"}}
263+
# AuthManager encrypts credentials and wraps them under 'credentials' key
264+
assert "credentials" in loaded
265+
assert "version" in loaded
266+
assert loaded["version"] == "2.0"
267+
# Verify the nested structure exists (encrypted value, not plaintext)
268+
assert "runpod" in loaded["credentials"]
264269

265270
def test_save_credentials_sets_permissions(self):
266271
"""Save credentials sets file permissions to 0600"""

tests/test_core_components.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,14 @@ class TestProviderRegistry:
129129
def test_new_provider_starts_healthy(self, registry):
130130
assert registry.is_healthy("runpod") is True
131131

132-
def test_circuit_breaker_opens_after_threshold(self, registry):
132+
async def test_circuit_breaker_opens_after_threshold(self, registry):
133133
for _ in range(registry.FAILURE_THRESHOLD):
134-
asyncio.get_event_loop().run_until_complete(
135-
registry.record_failure("runpod", "connection timeout")
136-
)
134+
await registry.record_failure("runpod", "connection timeout")
137135
assert registry.is_healthy("runpod") is False
138136

139-
def test_circuit_breaker_recovers_after_window(self, registry):
137+
async def test_circuit_breaker_recovers_after_window(self, registry):
140138
for _ in range(registry.FAILURE_THRESHOLD):
141-
asyncio.get_event_loop().run_until_complete(
142-
registry.record_failure("runpod", "timeout")
143-
)
139+
await registry.record_failure("runpod", "timeout")
144140
health = registry._get_health("runpod")
145141
health.last_failure_ts = time.time() - registry.RECOVERY_WINDOW_S - 1
146142
assert registry.is_healthy("runpod") is True
@@ -150,33 +146,29 @@ def test_provider_health_has_name(self, registry):
150146
health = registry._get_health("lambda_labs")
151147
assert health.provider == "lambda_labs"
152148

153-
def test_record_success_resets_failures(self, registry):
154-
loop = asyncio.get_event_loop()
155-
loop.run_until_complete(registry.record_failure("runpod", "err"))
156-
loop.run_until_complete(registry.record_success("runpod", latency_ms=50.0))
149+
async def test_record_success_resets_failures(self, registry):
150+
await registry.record_failure("runpod", "err")
151+
await registry.record_success("runpod", latency_ms=50.0)
157152
health = registry._get_health("runpod")
158153
assert health.consecutive_failures == 0
159154

160-
def test_latency_ema(self, registry):
161-
loop = asyncio.get_event_loop()
162-
loop.run_until_complete(registry.record_success("vastai", latency_ms=100.0))
163-
loop.run_until_complete(registry.record_success("vastai", latency_ms=200.0))
155+
async def test_latency_ema(self, registry):
156+
await registry.record_success("vastai", latency_ms=100.0)
157+
await registry.record_success("vastai", latency_ms=200.0)
164158
health = registry._get_health("vastai")
165159
assert 100.0 <= health.avg_latency_ms <= 200.0
166160

167161
def test_spot_score_zero_with_no_preemptions(self, registry):
168162
assert registry.get_spot_score("runpod") == 0.0
169163

170-
def test_spot_score_increases_after_preemptions(self, registry):
171-
loop = asyncio.get_event_loop()
164+
async def test_spot_score_increases_after_preemptions(self, registry):
172165
for _ in range(5):
173-
loop.run_until_complete(registry.record_preemption("runpod"))
166+
await registry.record_preemption("runpod")
174167
assert registry.get_spot_score("runpod") > 0.0
175168

176-
def test_ranked_providers_excludes_unhealthy(self, registry):
177-
loop = asyncio.get_event_loop()
169+
async def test_ranked_providers_excludes_unhealthy(self, registry):
178170
for _ in range(registry.FAILURE_THRESHOLD):
179-
loop.run_until_complete(registry.record_failure("runpod", "down"))
171+
await registry.record_failure("runpod", "down")
180172
ranked = registry.ranked_providers("H100-80GB")
181173
assert "runpod" not in ranked
182174

@@ -186,10 +178,9 @@ def test_get_stats_returns_correct_counts(self, registry):
186178
assert "overall_success_rate" in stats
187179
assert stats["overall_success_rate"] == 1.0
188180

189-
def test_reset_health(self, registry):
190-
loop = asyncio.get_event_loop()
181+
async def test_reset_health(self, registry):
191182
for _ in range(registry.FAILURE_THRESHOLD):
192-
loop.run_until_complete(registry.record_failure("runpod", "err"))
183+
await registry.record_failure("runpod", "err")
193184
registry.reset_health("runpod")
194185
assert registry.is_healthy("runpod") is True
195186
assert registry._get_health("runpod").consecutive_failures == 0

tests/test_providers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def _get_auth_headers(self):
7878
for gpu in ["A100", "V100", "H100", "RTX4090", "RTX3090"]:
7979
specs = p._get_gpu_specs(gpu)
8080
assert "memory_gb" in specs, f"Missing memory_gb for {gpu}"
81-
assert "tflops" in specs, f"Missing tflops for {gpu}"
81+
# _get_gpu_specs now returns tflops_bf16/tflops_fp16/tflops_fp32 instead of generic 'tflops'
82+
assert any(k in specs for k in ("tflops_bf16", "tflops_fp16", "tflops_fp32")), f"Missing tflops fields for {gpu}"
8283
assert specs["memory_gb"] > 0
8384

8485
def test_unknown_gpu_returns_empty(self):

0 commit comments

Comments
 (0)