Skip to content

Commit 0212730

Browse files
Add unit test for progress recording
1 parent b1e5761 commit 0212730

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

tilebox-workflows/tests/runner/test_runner.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from tilebox.workflows import ExecutionContext, Task
99
from tilebox.workflows.cache import InMemoryCache, JobCache
1010
from tilebox.workflows.client import Client
11-
from tilebox.workflows.data import JobState, RunnerContext
11+
from tilebox.workflows.data import JobState, ProgressBar, RunnerContext
1212
from tilebox.workflows.runner.task_runner import TaskRunner
1313

1414

@@ -115,6 +115,40 @@ def test_runner_with_flaky_task() -> None:
115115
assert job.state == JobState.COMPLETED
116116

117117

118+
class ProgressTask(Task):
119+
n: int
120+
121+
def execute(self, context: ExecutionContext) -> None:
122+
context.progress("test").add(self.n)
123+
context.submit_subtasks([ProgressLeafTask(i) for i in range(self.n)])
124+
125+
126+
class ProgressLeafTask(Task):
127+
i: int
128+
129+
def execute(self, context: ExecutionContext) -> None:
130+
context.progress("test").done(1)
131+
132+
133+
def test_runner_with_workflow_tracking_progress() -> None:
134+
client = replay_client("progress.rpcs.bin")
135+
job_client = client.jobs()
136+
137+
with patch("tilebox.workflows.jobs.client.get_trace_parent_of_current_span") as get_trace_parent_mock:
138+
# we hardcode the trace parent for the job, which allows us to assert that every single outgoing request
139+
# matches exactly byte for byte
140+
get_trace_parent_mock.return_value = "00-98b9c13dbc61637ffb36f592a8236088-bc29f6909f0b7c5b-01"
141+
job = client.jobs().submit("progress-task", ProgressTask(4))
142+
143+
cache = InMemoryCache()
144+
runner = client.runner(tasks=[ProgressTask, ProgressLeafTask], cache=cache)
145+
146+
runner.run_all()
147+
job = job_client.find(job) # load current job state
148+
assert job.state == JobState.COMPLETED
149+
assert job.progress_bars == [ProgressBar("test", 4, 4)]
150+
151+
118152
def replay_client(replay_file: str, assert_request_matches: bool = True) -> Client:
119153
replay = Path(__file__).parent / "testdata" / "recordings" / replay_file
120154
replay_channel = open_replay_channel(replay, assert_request_matches)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:e461b7a7f2a06f0be20962237c6f73beecbb72020f06b9b076ea26a9139a6420
3+
size 4467

0 commit comments

Comments
 (0)