1515from .types import MockUser
1616
1717
18+ async def wait_for_assistant_service_registration (
19+ wb_client : httpx .AsyncClient ,
20+ ) -> workbench_model .AssistantServiceRegistration :
21+ for _ in range (5 ):
22+ http_response = await wb_client .get ("/assistant-service-registrations" )
23+ http_response .raise_for_status ()
24+ assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (http_response .json ())
25+ if assistant_services .assistant_service_registrations :
26+ return assistant_services .assistant_service_registrations [0 ]
27+
28+ await asyncio .sleep (0.001 )
29+
30+ raise Exception ("Timed out waiting for assistant service registration" )
31+
32+
1833async def test_flow_create_assistant_update_config (
1934 workbench_service : FastAPI ,
2035 canonical_assistant_service : FastAPI ,
@@ -29,11 +44,7 @@ async def test_flow_create_assistant_update_config(
2944 ) as wb_client ,
3045 LifespanManager (canonical_assistant_service ),
3146 ):
32- resp = await wb_client .get ("/assistant-service-registrations" )
33- resp .raise_for_status ()
34- assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (resp .json ())
35- assert len (assistant_services .assistant_service_registrations ) == 1
36- assistant_service = assistant_services .assistant_service_registrations [0 ]
47+ assistant_service = await wait_for_assistant_service_registration (wb_client )
3748
3849 resp = await wb_client .post (
3950 "/assistants" ,
@@ -82,11 +93,7 @@ async def test_flow_create_assistant_update_conversation_state(
8293 ) as wb_client ,
8394 LifespanManager (canonical_assistant_service ),
8495 ):
85- resp = await wb_client .get ("/assistant-service-registrations" )
86- resp .raise_for_status ()
87- assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (resp .json ())
88- assert len (assistant_services .assistant_service_registrations ) == 1
89- assistant_service = assistant_services .assistant_service_registrations [0 ]
96+ assistant_service = await wait_for_assistant_service_registration (wb_client )
9097
9198 resp = await wb_client .post (
9299 "/assistants" ,
@@ -170,11 +177,7 @@ async def test_flow_create_assistant_send_message_receive_resp(
170177 ) as wb_client ,
171178 LifespanManager (canonical_assistant_service ),
172179 ):
173- resp = await wb_client .get ("/assistant-service-registrations" )
174- resp .raise_for_status ()
175- assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (resp .json ())
176- assert len (assistant_services .assistant_service_registrations ) == 1
177- assistant_service = assistant_services .assistant_service_registrations [0 ]
180+ assistant_service = await wait_for_assistant_service_registration (wb_client )
178181
179182 resp = await wb_client .post (
180183 "/assistants" ,
@@ -235,11 +238,7 @@ async def test_flow_create_assistant_send_message_receive_resp_export_import_ass
235238 ) as wb_client ,
236239 LifespanManager (canonical_assistant_service ),
237240 ):
238- resp = await wb_client .get ("/assistant-service-registrations" )
239- resp .raise_for_status ()
240- assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (resp .json ())
241- assert len (assistant_services .assistant_service_registrations ) == 1
242- assistant_service = assistant_services .assistant_service_registrations [0 ]
241+ assistant_service = await wait_for_assistant_service_registration (wb_client )
243242
244243 resp = await wb_client .post (
245244 "/assistants" ,
@@ -354,11 +353,7 @@ async def test_flow_create_assistant_send_message_receive_resp_export_import_con
354353 ) as wb_client ,
355354 LifespanManager (canonical_assistant_service ),
356355 ):
357- resp = await wb_client .get ("/assistant-service-registrations" )
358- resp .raise_for_status ()
359- assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (resp .json ())
360- assert len (assistant_services .assistant_service_registrations ) == 1
361- assistant_service = assistant_services .assistant_service_registrations [0 ]
356+ assistant_service = await wait_for_assistant_service_registration (wb_client )
362357
363358 resp = await wb_client .post (
364359 "/assistants" ,
@@ -485,11 +480,7 @@ async def test_flow_create_assistant_send_command_message_receive_resp(
485480 ) as wb_client ,
486481 LifespanManager (canonical_assistant_service ),
487482 ):
488- resp = await wb_client .get ("/assistant-service-registrations" )
489- resp .raise_for_status ()
490- assistant_services = workbench_model .AssistantServiceRegistrationList .model_validate (resp .json ())
491- assert len (assistant_services .assistant_service_registrations ) == 1
492- assistant_service = assistant_services .assistant_service_registrations [0 ]
483+ assistant_service = await wait_for_assistant_service_registration (wb_client )
493484
494485 resp = await wb_client .post (
495486 "/assistants" ,
0 commit comments