Skip to content

Commit

Permalink
Fix worker filter param (#15804)
Browse files Browse the repository at this point in the history
Co-authored-by: zzstoatzz <thrast36@gmail.com>
  • Loading branch information
zangell44 and zzstoatzz authored Oct 24, 2024
1 parent 9cc497e commit a17ccfc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/prefect/client/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,7 @@ async def read_workers_for_work_pool(
response = await self._client.post(
f"/work_pools/{work_pool_name}/workers/filter",
json={
"worker_filter": (
"workers": (
worker_filter.model_dump(mode="json", exclude_unset=True)
if worker_filter
else None
Expand Down
37 changes: 37 additions & 0 deletions tests/server/orchestration/api/test_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,43 @@ async def test_worker_status_accounts_for_heartbeat_interval(
assert workers_response.json()[0]["status"] == "OFFLINE"


class TestReadWorkers:
@pytest.fixture
async def setup_workers(self, session, db, work_pool):
# Create an ONLINE worker via heartbeat
await models.workers.worker_heartbeat(
session=session,
work_pool_id=work_pool.id,
worker_name="online-worker",
)

insert_stmt = db.insert(db.Worker).values(
name="offline-worker",
work_pool_id=work_pool.id,
status="OFFLINE",
)
await session.execute(insert_stmt)

await session.commit()

async def test_read_workers(self, client, work_pool):
response = await client.post(f"/work_pools/{work_pool.name}/workers/filter")
assert response.status_code == status.HTTP_200_OK

@pytest.mark.usefixtures("setup_workers")
@pytest.mark.parametrize("worker_status", ["ONLINE", "OFFLINE"])
async def test_read_workers_filter_by_status(
self, client, work_pool, worker_status
):
response = await client.post(
f"/work_pools/{work_pool.name}/workers/filter",
json=dict(workers=dict(status=dict(any_=[worker_status]))),
)
assert response.status_code == status.HTTP_200_OK, response.text
assert len(data := response.json()) == 1, data
assert data[0]["status"] == worker_status


class TestDeleteWorker:
async def test_delete_worker(self, client, work_pool, session, db):
work_pool_id = work_pool.id
Expand Down

0 comments on commit a17ccfc

Please sign in to comment.