@@ -965,41 +965,57 @@ def test_send_recv_workflow(topic: str) -> str:
965965def test_set_get_events (dbos : DBOS ) -> None :
966966 @DBOS .workflow ()
967967 def test_setevent_workflow () -> None :
968- dbos .set_event ("key1" , "value1" )
969- dbos .set_event ("key2" , "value2" )
970- dbos .set_event ("key3" , None )
968+ DBOS .set_event ("key1" , "value1" )
969+ DBOS .set_event ("key2" , "value2" )
970+ DBOS .set_event ("key3" , None )
971+ set_event_step ()
972+
973+ @DBOS .step ()
974+ def set_event_step () -> None :
975+ DBOS .set_event ("key4" , "value4" )
971976
972977 @DBOS .workflow ()
973978 def test_getevent_workflow (
974- target_uuid : str , key : str , timeout_seconds : float = 10
979+ target_uuid : str , key : str , timeout : float = 0.0
975980 ) -> Optional [str ]:
976- msg = dbos .get_event (target_uuid , key , timeout_seconds )
981+ msg = dbos .get_event (target_uuid , key , timeout )
977982 return str (msg ) if msg is not None else None
978983
979- wfuuid = str (uuid .uuid4 ())
980- with SetWorkflowID (wfuuid ):
984+ wfid = str (uuid .uuid4 ())
985+ with SetWorkflowID (wfid ):
981986 test_setevent_workflow ()
982- with SetWorkflowID (wfuuid ):
987+ with SetWorkflowID (wfid ):
983988 test_setevent_workflow ()
984989
985- value1 = test_getevent_workflow (wfuuid , "key1" )
990+ value1 = test_getevent_workflow (wfid , "key1" )
986991 assert value1 == "value1"
987992
988- value2 = test_getevent_workflow (wfuuid , "key2" )
993+ value2 = test_getevent_workflow (wfid , "key2" )
989994 assert value2 == "value2"
990995
991996 # Run getEvent outside of a workflow
992- value1 = dbos .get_event (wfuuid , "key1" )
997+ value1 = DBOS .get_event (wfid , "key1" , 0 )
993998 assert value1 == "value1"
994999
995- value2 = dbos .get_event (wfuuid , "key2" )
1000+ value2 = DBOS .get_event (wfid , "key2" , 0 )
9961001 assert value2 == "value2"
9971002
9981003 begin_time = time .time ()
999- value3 = test_getevent_workflow (wfuuid , "key3" )
1004+ value3 = test_getevent_workflow (wfid , "key3" )
10001005 assert value3 is None
1001- duration = time .time () - begin_time
1002- assert duration < 1 # None is from the event not from the timeout
1006+
1007+ value4 = DBOS .get_event (wfid , "key4" , 0 )
1008+ assert value4 == "value4"
1009+
1010+ steps = DBOS .list_workflow_steps (wfid )
1011+ assert len (steps ) == 4
1012+ assert (
1013+ steps [0 ]["function_name" ]
1014+ == steps [1 ]["function_name" ]
1015+ == steps [2 ]["function_name" ]
1016+ == "DBOS.setEvent"
1017+ )
1018+ assert steps [3 ]["function_name" ] == set_event_step .__qualname__
10031019
10041020 # Test OAOO
10051021 timeout_uuid = str (uuid .uuid4 ())
0 commit comments