Files
hatchet/sdks/python/tests/test_rest_api.py
Matt Kaye 993817b049 [Python] Single listener base class + bug fixes + refactors (#1470)
* fix: register durable steps and workflows separately

* chore: initial copy of pooled listener

* feat: initial generic impl

* feat: use pooled listener for wf run listener

* refactor: move listeners to subdir

* feat: refactor durable event listener

* fix: bug

* feat: share single pooled workflow listener and event listener everywhere

* cruft: rm hatchet fixture

* fix: rebase issue

* feat: remove asyncio api client in favor of sync one

* chore: minor version

* proposal: crazy hack idea to make the workflow run listener work

* fix: sleeps and error handling

* Revert "cruft: rm hatchet fixture"

This reverts commit b75f625e6ccec095e8c4e294d6727db166796411.

* fix: set timeout

* fix: rm pytest-timeout

* fix: rm retry

* fix: use v1 by default

* fix: try removing retry state

* fix: try using async client?

* fix: try running sequentially

* debug: loop

* debug: maybe it's this?

* fix: lint

* fix: re-remove unused fixtures

* fix: lazily create clients in admin client

* fix: default

* fix: lazily initialize dispatcher client

* fix: hint

* fix: no. way.

* feat: add back retries in ci

* fix: clients + imports

* fix: loop scope

* debug: try running skipped tests in ci again

* Revert "debug: try running skipped tests in ci again"

This reverts commit 8d9e18150e5207ee6051d8df8a6fe2a7504c722e.

* fix: rm duped code

* refactor: rename everything as `to_proto`

* refactor: removals of `namespace` being passed around

* fix: task output stupidity

* feat: add deprecation warning

* fix: remove more unused code

* feat: mix sync and async in dag example

* fix: autouse

* fix: more input types

* feat: remove ability to pass in loop

* fix: overload key gen
2025-04-10 08:18:17 -04:00

55 lines
1.6 KiB
Python

import asyncio
import pytest
from examples.dag.worker import dag_workflow
from hatchet_sdk import Hatchet
@pytest.mark.asyncio(loop_scope="session")
async def test_list_runs(hatchet: Hatchet) -> None:
dag_result = await dag_workflow.aio_run()
runs = await hatchet.runs.aio_list(
limit=10_000,
only_tasks=True,
)
for v in dag_result.values():
assert v in [r.output for r in runs.rows]
@pytest.mark.asyncio(loop_scope="session")
async def test_get_run(hatchet: Hatchet) -> None:
dag_ref = await dag_workflow.aio_run_no_wait()
await asyncio.sleep(5)
run = await hatchet.runs.aio_get(dag_ref.workflow_run_id)
assert dag_workflow.config.name in run.run.display_name
assert run.run.status.value == "COMPLETED"
assert len(run.shape) == 4
assert {t.name for t in dag_workflow.tasks} == {t.task_name for t in run.shape}
@pytest.mark.asyncio(loop_scope="session")
async def test_list_workflows(hatchet: Hatchet) -> None:
workflows = await hatchet.workflows.aio_list(
workflow_name=dag_workflow.config.name, limit=1, offset=0
)
assert workflows.rows
assert len(workflows.rows) == 1
workflow = workflows.rows[0]
"""Using endswith because of namespacing in CI"""
assert workflow.name.endswith(dag_workflow.config.name)
fetched_workflow = await hatchet.workflows.aio_get(workflow.metadata.id)
"""Using endswith because of namespacing in CI"""
assert fetched_workflow.name.endswith(dag_workflow.config.name)
assert fetched_workflow.metadata.id == workflow.metadata.id