@@ -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
0 commit comments