Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions integration-tests/test_upsert_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest
import asyncio
from pydantic import BaseModel
Comment thread
NiveditJain marked this conversation as resolved.
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

Comment thread
NiveditJain marked this conversation as resolved.

state_machine_url = running_server.base_url
Comment thread
NiveditJain marked this conversation as resolved.
runtime = Runtime(
namespace="test",
name="test",
nodes=[
PrintNode
],
state_manager_uri=state_machine_url,
)

# Use asyncio task instead of thread for proper cleanup
runtime_task = None

try:
# Start runtime as an asyncio task (non-blocking)
runtime_task = asyncio.create_task(runtime._start())

# Give runtime time to initialize
await asyncio.sleep(2)

Comment thread
NiveditJain marked this conversation as resolved.
Outdated
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="PrintNode",
namespace="test",
identifier="node1",
inputs={
"message": "Hello, world!",
},
)
],
secrets={},
)
assert data is not None

Comment thread
NiveditJain marked this conversation as resolved.
Outdated
finally:
# Ensure proper cleanup of the runtime task
if runtime_task and not runtime_task.done():
runtime_task.cancel()
try:
await runtime_task
except asyncio.CancelledError:
pass # Expected when cancelling
Loading