Skip to content

Commit c09419a

Browse files
committed
CI: harden test execution
1 parent 05a4239 commit c09419a

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
./deploy.sh -g -D /mnt/data/docker -W /mnt/data/workspace ${{ matrix.mode == 'multinode' && '-M' || '' }} -C
134134
135135
- name: Run ${{ matrix.mode }} dojo tests
136-
timeout-minutes: 15
136+
timeout-minutes: 20
137137
run: |
138138
./deploy.sh -g -D /mnt/data/docker -W /mnt/data/workspace ${{ matrix.mode == 'multinode' && '-M' || '' }} -C -N -t
139139

test/test_background_stats.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

244244
def 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

260285
def test_cache_structure(stats_test_dojo, stats_test_user):
261286
user_name, user_session = stats_test_user

test/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ def dojo_run(*args, **kwargs):
122122

123123

124124
def db_sql(sql):
125-
db_result = dojo_run("dojo", "db", "-qAt", input=sql)
126-
return db_result.stdout
125+
db_result = dojo_run(
126+
"dojo", "db", "-v", "ON_ERROR_STOP=1", "-qAt", input=sql,
127+
check=False,
128+
)
129+
assert db_result.returncode == 0, db_result.stderr
130+
return db_result.stdout
127131

128132

129133
def get_user_id(user_name):

0 commit comments

Comments
 (0)