|
| 1 | +from datetime import timedelta |
1 | 2 | from time import sleep
|
2 | 3 | from uuid import uuid4
|
3 | 4 |
|
@@ -103,7 +104,6 @@ def test_workflow_job_completed(
|
103 | 104 | def test_workflow_job_in_progress(
|
104 | 105 | webhook: WorkflowJobInProgress, queue: Queue, settings: Settings, redis: Redis
|
105 | 106 | ):
|
106 |
| - |
107 | 107 | # flush all keys that start with settings.name in redis
|
108 | 108 |
|
109 | 109 | init_model(Runner, redis, settings)
|
@@ -197,3 +197,61 @@ def test_workflow_job_queued(
|
197 | 197 | ).first()
|
198 | 198 | assert runner.busy is False
|
199 | 199 | assert runner.status == "offline"
|
| 200 | + |
| 201 | + |
| 202 | +@settings(max_examples=10) |
| 203 | +@given( |
| 204 | + webhook=WorkflowJobInProgressStrategy, |
| 205 | + queue=QueueStrategy, |
| 206 | + settings=SettingsStrategy, |
| 207 | + redis=RedisStrategy, |
| 208 | +) |
| 209 | +def test_workflow_job_time_to_start( |
| 210 | + webhook: WorkflowJobInProgress, queue: Queue, settings: Settings, redis: Redis |
| 211 | +): |
| 212 | + """ |
| 213 | + This test will ensure that an extra runner is created when the time to start |
| 214 | + the given workflow was higher than settings.timeout_runners. |
| 215 | + """ |
| 216 | + init_model(Runner, redis, settings) |
| 217 | + init_model(RunnerGroup, redis, settings) |
| 218 | + runner_group: RunnerGroup = RunnerGroup( |
| 219 | + organization=webhook.organization.login, |
| 220 | + name=webhook.workflow_job.runner_group_name, |
| 221 | + id=webhook.workflow_job.runner_group_id, |
| 222 | + labels=webhook.workflow_job.labels, |
| 223 | + manager=settings.name, |
| 224 | + backend={"name": "base"}, |
| 225 | + max=2, |
| 226 | + ) |
| 227 | + runner_group.save() |
| 228 | + Migrator().run() |
| 229 | + |
| 230 | + runner: Runner = Runner( |
| 231 | + id=webhook.workflow_job.runner_id, |
| 232 | + name=webhook.workflow_job.runner_name, |
| 233 | + busy=False, |
| 234 | + status="online", |
| 235 | + manager=settings.name, |
| 236 | + runner_group_id=webhook.workflow_job.runner_group_id, |
| 237 | + runner_group_name=webhook.workflow_job.runner_group_name, |
| 238 | + ) |
| 239 | + runner.save() |
| 240 | + Migrator().run() |
| 241 | + |
| 242 | + assert len(runner_group.get_runners()) == 1 |
| 243 | + # ensure we have only one runner if the time to start is less than timeout_runners |
| 244 | + webhook.workflow_job.started_at = webhook.workflow_job.created_at + ( |
| 245 | + settings.timeout_runner - timedelta(minutes=15) |
| 246 | + ) |
| 247 | + queue.enqueue(workflow_job.in_progress, webhook) |
| 248 | + assert len(runner_group.get_runners()) == 1 |
| 249 | + # ensure we have two runners if the time to start is greater than timeout_runners |
| 250 | + webhook.workflow_job.started_at = webhook.workflow_job.created_at + ( |
| 251 | + settings.timeout_runner + timedelta(minutes=15) |
| 252 | + ) |
| 253 | + queue.enqueue(workflow_job.in_progress, webhook) |
| 254 | + assert len(runner_group.get_runners()) == 2 |
| 255 | + # ensure we remain with two runners given that the max for the runner group is 2 |
| 256 | + queue.enqueue(workflow_job.in_progress, webhook) |
| 257 | + assert len(runner_group.get_runners()) == 2 |
0 commit comments