Skip to content

Commit 452c2ad

Browse files
rtibblesbotclaude
andcommitted
Assert the lifecycle job is owned while RUNNING
Read back orm_job.supervisor_id mid-execution to prove ownership is held for the duration, not merely cleared on completion. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 94cf709 commit 452c2ad

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

platforms/android/app/src/main/python/tests/test_lifecycle.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
"""
66

77
from django.test import TestCase
8+
from task_identity import supervisor_id_from_request
89

910
from kolibri.core.tasks.job import Job
1011
from kolibri.core.tasks.job import State
1112
from kolibri.core.tasks.main import job_storage
1213

14+
# Captured mid-execution to prove the job is owned while RUNNING, not just
15+
# that ownership is cleared afterwards.
16+
_observed = {}
1317

14-
def _noop_task(**kwargs):
18+
19+
def _observe_ownership_task(**kwargs):
20+
orm_job = job_storage.get_orm_job(_observed["job_id"])
21+
_observed["state"] = orm_job.state
22+
_observed["supervisor_id"] = orm_job.supervisor_id
1523
return "ok"
1624

1725

@@ -21,11 +29,21 @@ class TaskWorkerLifecycleTest(TestCase):
2129
def test_execute_via_request_id_reaches_completed(self):
2230
import taskworker
2331

24-
job = Job(_noop_task)
32+
job = Job(_observe_ownership_task)
2533
job_id = job_storage.enqueue_job(job)
34+
_observed.clear()
35+
_observed["job_id"] = job_id
2636

2737
# A canonical (dashed) java.util.UUID.toString() request id.
28-
taskworker.execute_job(job_id, "3f2504e0-4f89-41d3-9a0c-0305e82c3301")
38+
request_id = "3f2504e0-4f89-41d3-9a0c-0305e82c3301"
39+
taskworker.execute_job(job_id, request_id)
40+
41+
# Mid-execution: the job was RUNNING and owned by the normalized id.
42+
self.assertEqual(_observed["state"], State.RUNNING)
43+
self.assertEqual(
44+
_observed["supervisor_id"],
45+
supervisor_id_from_request(request_id),
46+
)
2947

3048
orm_job = job_storage.get_orm_job(job_id)
3149
self.assertEqual(orm_job.state, State.COMPLETED)

0 commit comments

Comments
 (0)