forked from FailproofAI/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_upsert_graph.py
More file actions
64 lines (54 loc) · 1.77 KB
/
Copy pathtest_upsert_graph.py
File metadata and controls
64 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pytest
import asyncio
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
state_machine_url = running_server.base_url
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)
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
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