Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Add integration test for upserting graph in StateManager#353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
06efe2414cceb0f425acaa6e9d30File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import pytest | ||
| import asyncio | ||
| import threading | ||
| import os | ||
| from aiohttp import ClientSession | ||
| from pydantic import BaseModel | ||
| from exospherehost import BaseNode, Runtime, StateManager, GraphNodeModel | ||
| @pytest.mark.asyncio | ||
| async def test_upsert_graph(running_server): | ||
| class Node1(BaseNode): | ||
| class Inputs(BaseModel): | ||
| message: str | ||
| class Outputs(BaseModel): | ||
| count: str | ||
| async def execute(self): | ||
| return [self.Outputs(count=str(i)) for i in range(10)] | ||
| state_machine_url = running_server.base_url | ||
| runtime = Runtime( | ||
| namespace="test", | ||
| name="test", | ||
| nodes=[ | ||
| Node1 | ||
| ], | ||
| state_manager_uri=state_machine_url, | ||
| ) | ||
| thread = threading.Thread(target=runtime.start, daemon=True) | ||
| thread.start() | ||
| await asyncio.sleep(2) | ||
| state_manager = StateManager( | ||
| namespace="test", | ||
| state_manager_uri=state_machine_url, | ||
| ) | ||
| data = await state_manager.upsert_graph( | ||
| graph_name="test_graph", | ||
| graph_nodes=[ | ||
| GraphNodeModel( | ||
| node_name="Node1", | ||
| namespace="test", | ||
| identifier="node1", | ||
| inputs={ | ||
| "message": "Hello, world!", | ||
| }, | ||
| ) | ||
| ], | ||
| secrets={}, | ||
| ) | ||
| assert data is not None | ||
| assert data["validation_status"] == "VALID" | ||
| trigger = await state_manager.trigger( | ||
| graph_name="test_graph", | ||
| inputs={}, | ||
| ) | ||
| assert trigger is not None | ||
| assert "run_id" in trigger | ||
| run_id = trigger["run_id"] | ||
| await asyncio.sleep(30) | ||
| run_object = None | ||
| async with ClientSession() as session: | ||
| async with session.get(f"{state_machine_url}/v0/namespace/test/runs/1/100", headers={"x-api-key": os.getenv("EXOSPHERE_API_KEY")}) as response: # type: ignore | ||
| assert response.status == 200 | ||
| data = await response.json() | ||
| assert "runs" in data | ||
| for run in data["runs"]: | ||
| if run["run_id"] == run_id: | ||
| run_object = run | ||
| break | ||
| assert run_object is not None | ||
| assert run_object["run_id"] == run_id | ||
| assert run_object["graph_name"] == "test_graph" | ||
| assert run_object["success_count"] == 10 | ||
| assert run_object["pending_count"] == 0 | ||
| assert run_object["errored_count"] == 0 | ||
| assert run_object["retried_count"] == 0 | ||
| assert run_object["total_count"] == 10 | ||
| assert run_object["status"] == "SUCCESS" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import pytest | ||
| import asyncio | ||
| import threading | ||
| from pydantic import BaseModel | ||
| from exospherehost import BaseNode, Runtime, StateManager, GraphNodeModel | ||
| @pytest.mark.asyncio | ||
| async def test_upsert_graph(running_server): | ||
| class PrintNode(BaseNode): | ||
| class Inputs(BaseModel): | ||
| message: str | ||
| async def execute(self): | ||
| print(self.inputs.message) # type: ignore | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| state_machine_url = running_server.base_url | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| runtime = Runtime( | ||
| namespace="test", | ||
| name="test", | ||
| nodes=[ | ||
| PrintNode | ||
| ], | ||
| state_manager_uri=state_machine_url, | ||
| ) | ||
| thread = threading.Thread(target=runtime.start, daemon=True) | ||
| thread.start() | ||
| await asyncio.sleep(2) | ||
| state_manager = StateManager( | ||
| namespace="test", | ||
| state_manager_uri=state_machine_url, | ||
| ) | ||
| data = await state_manager.upsert_graph( | ||
| graph_name="test_graph", | ||
| graph_nodes=[ | ||
| GraphNodeModel( | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| node_name="PrintNode", | ||
| namespace="test", | ||
| identifier="node1", | ||
| inputs={ | ||
| "message": "Hello, world!", | ||
| }, | ||
| ) | ||
| ], | ||
| secrets={}, | ||
| ) | ||
| assert data is not None | ||
| assert data["validation_status"] == "VALID" | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.