@@ -242,12 +242,36 @@ def test_multiple_solves_update_stats(stats_test_dojo, stats_test_user):
242242 assert second_solves > first_solves , f"Expected solves to increase from { first_solves } to more, got { second_solves } "
243243
244244def test_cold_start_initializes_cache (example_dojo ):
245- cache_key = f"stats:dojo:{ example_dojo } "
246- cached_data = redis_get (cache_key )
245+ official_dojo_id = example_dojo .split ("~" , 1 )[0 ]
246+ cache_key = f"stats:dojo:{ official_dojo_id } "
247+ stop = dojo_run (
248+ "docker" , "stop" , "--time" , "1" , "stats-worker" , check = False
249+ )
250+ assert stop .returncode == 0 , stop .stderr
251+ redis_delete (cache_key , f"{ cache_key } :updated" )
252+ assert redis_get (cache_key ) is None
253+ assert redis_get (f"{ cache_key } :updated" ) is None
254+ start_time = time .time ()
255+ start = dojo_run ("docker" , "start" , "stats-worker" , check = False )
256+ assert start .returncode == 0 , start .stderr
257+ deadline = time .time () + 30
258+ worker_logs = None
259+ worker_output = ""
260+ while time .time () < deadline :
261+ worker_logs = dojo_run (
262+ "docker" , "logs" , "stats-worker" , "--since" ,
263+ str (start_time ), check = False ,
264+ )
265+ worker_output = worker_logs .stdout + worker_logs .stderr
266+ if "Cold start complete" in worker_output :
267+ break
268+ time .sleep (0.2 )
269+ assert worker_logs is not None
270+ assert "Cold start complete" in worker_output , worker_output
271+ assert f"Initialized stats for dojo { official_dojo_id } " in worker_output
247272
248- if cached_data is None :
249- result = dojo_run ("docker" , "logs" , "stats-worker" , "--tail" , "100" , check = False )
250- pytest .fail (f"Cold start should have initialized cache for { example_dojo } . Worker logs:\n { result .stdout } " )
273+ cached_data = redis_get (cache_key )
274+ assert cached_data is not None
251275
252276 stats = json .loads (cached_data )
253277 assert 'solves' in stats
@@ -256,6 +280,7 @@ def test_cold_start_initializes_cache(example_dojo):
256280
257281 timestamp = redis_get (f"{ cache_key } :updated" )
258282 assert timestamp is not None , "Cache timestamp should exist from cold start"
283+ assert float (timestamp ) >= start_time
259284
260285def test_cache_structure (stats_test_dojo , stats_test_user ):
261286 user_name , user_session = stats_test_user
0 commit comments