|
8 | 8 | from tilebox.workflows import ExecutionContext, Task |
9 | 9 | from tilebox.workflows.cache import InMemoryCache, JobCache |
10 | 10 | from tilebox.workflows.client import Client |
11 | | -from tilebox.workflows.data import JobState, RunnerContext |
| 11 | +from tilebox.workflows.data import JobState, ProgressBar, RunnerContext |
12 | 12 | from tilebox.workflows.runner.task_runner import TaskRunner |
13 | 13 |
|
14 | 14 |
|
@@ -115,6 +115,40 @@ def test_runner_with_flaky_task() -> None: |
115 | 115 | assert job.state == JobState.COMPLETED |
116 | 116 |
|
117 | 117 |
|
| 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 | + |
118 | 152 | def replay_client(replay_file: str, assert_request_matches: bool = True) -> Client: |
119 | 153 | replay = Path(__file__).parent / "testdata" / "recordings" / replay_file |
120 | 154 | replay_channel = open_replay_channel(replay, assert_request_matches) |
|
0 commit comments