@@ -838,11 +838,11 @@ impl TestServer {
838838 . expect ( "events parse failed" )
839839 }
840840
841- async fn get_logs ( & self , execution_id : & str ) -> Value {
841+ async fn get_logs ( & self , execution_id : & str , length : usize ) -> Value {
842842 self . client
843843 . get ( format ! (
844- "{}/v1/executions/{execution_id}/logs?length=100 &direction=newer" ,
845- self . base_url
844+ "{}/v1/executions/{execution_id}/logs?length={length} &direction=newer" ,
845+ self . base_url,
846846 ) )
847847 . header ( "Accept" , "application/json" )
848848 . send ( )
@@ -1722,7 +1722,7 @@ impl TestServer {
17221722 ExecutionRepositoryClient :: connect ( format ! ( "http://{}" , self . api_addr( ) ) )
17231723 . await
17241724 . unwrap ( ) ;
1725- for _ in 0 .. 200 {
1725+ loop {
17261726 if let Ok ( resp) = grpc_client
17271727 . cancel_execution ( CancelExecutionRequest {
17281728 execution_id : Some ( GrpcExecutionId {
@@ -1736,12 +1736,11 @@ impl TestServer {
17361736 }
17371737 tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
17381738 }
1739- panic ! ( "execution {execution_id} was never cancellable" ) ;
17401739 }
17411740
17421741 /// Cancel a delay out-of-band, retrying until the workflow has submitted it.
17431742 async fn cancel_delay_with_retries ( & self , delay_id : & str ) {
1744- for _ in 0 .. 200 {
1743+ loop {
17451744 let resp = self
17461745 . client
17471746 . put ( format ! ( "{}/v1/delays/{delay_id}/cancel" , self . base_url) )
@@ -1754,7 +1753,6 @@ impl TestServer {
17541753 }
17551754 tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
17561755 }
1757- panic ! ( "delay {delay_id} was never cancellable" ) ;
17581756 }
17591757
17601758 async fn step_execution_until_finished_grpc (
@@ -2752,9 +2750,13 @@ async fn greet_activity_logs() {
27522750 // Consume the streamed body to wait for execution to finish.
27532751 let _: Value = resp. json ( ) . await . unwrap ( ) ;
27542752
2755- // Allow log forwarding to flush.
2756- tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
2757- let logs = server. get_logs ( & exec_id) . await ;
2753+ let logs = loop {
2754+ let logs = server. get_logs ( & exec_id, 1 ) . await ;
2755+ if logs. as_array ( ) . expect ( "logs must be an array" ) . len ( ) == 1 {
2756+ break logs;
2757+ }
2758+ tokio:: time:: sleep ( Duration :: from_millis ( 50 ) ) . await ;
2759+ } ;
27582760 let logs = sanitize_json ( & logs) ;
27592761 insta:: assert_json_snapshot!( "greet_activity_logs" , logs) ;
27602762 server. shutdown ( ) . await ;
@@ -2853,8 +2855,7 @@ async fn cancel_execution_grpc_routes_activities_and_cancellable_workflows() {
28532855 ) ;
28542856 // Cancelling a paused activity is async: the driver finalizes it to
28552857 // Finished(Cancelled) on a later tick, so poll rather than asserting immediately.
2856- let mut activity_finished = false ;
2857- for _ in 0 ..100 {
2858+ loop {
28582859 let summary = server. get_status_summary_grpc ( & activity_id) . await ;
28592860 if matches ! (
28602861 summary
@@ -2863,12 +2864,10 @@ async fn cancel_execution_grpc_routes_activities_and_cancellable_workflows() {
28632864 . and_then( |status| status. status. as_ref( ) ) ,
28642865 Some ( grpc:: grpc_gen:: execution_status:: Status :: Finished ( _) )
28652866 ) {
2866- activity_finished = true ;
28672867 break ;
28682868 }
28692869 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
28702870 }
2871- assert ! ( activity_finished, "cancelled paused activity must finish" ) ;
28722871
28732872 let cancellable_workflow_id = server
28742873 . seed_cancellable_parent_blocked_on_uncancellable_child ( )
@@ -2961,8 +2960,7 @@ async fn cancel_execution_webapi_routes_activities_and_cancellable_workflows() {
29612960 ) ;
29622961 // Cancelling a paused activity is async: the driver finalizes it to
29632962 // Finished(Cancelled) on a later tick, so poll rather than asserting immediately.
2964- let mut activity_finished = false ;
2965- for _ in 0 ..100 {
2963+ loop {
29662964 let summary = server. get_status_summary_grpc ( & activity_id) . await ;
29672965 if matches ! (
29682966 summary
@@ -2971,12 +2969,10 @@ async fn cancel_execution_webapi_routes_activities_and_cancellable_workflows() {
29712969 . and_then( |status| status. status. as_ref( ) ) ,
29722970 Some ( grpc:: grpc_gen:: execution_status:: Status :: Finished ( _) )
29732971 ) {
2974- activity_finished = true ;
29752972 break ;
29762973 }
29772974 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
29782975 }
2979- assert ! ( activity_finished, "cancelled paused activity must finish" ) ;
29802976
29812977 let cancellable_workflow_id = server
29822978 . seed_cancellable_parent_blocked_on_uncancellable_child ( )
@@ -3084,8 +3080,7 @@ async fn cancellation_driver_finishes_running_cancellable_workflow_as_cancelled(
30843080 . unwrap ( ) ;
30853081
30863082 // Wait until it has run and created the delay (blocked, or kept warm-locked).
3087- let mut started = false ;
3088- for _ in 0 ..100 {
3083+ loop {
30893084 let status = server. get_status_summary_grpc ( & exec_id) . await ;
30903085 if matches ! (
30913086 status
@@ -3094,12 +3089,10 @@ async fn cancellation_driver_finishes_running_cancellable_workflow_as_cancelled(
30943089 . and_then( |status| status. status. as_ref( ) ) ,
30953090 Some ( Status :: BlockedByJoinSet ( _) | Status :: Locked ( _) )
30963091 ) {
3097- started = true ;
30983092 break ;
30993093 }
31003094 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
31013095 }
3102- assert ! ( started, "workflow never started/blocked on the sleep" ) ;
31033096
31043097 let resp = grpc_client
31053098 . cancel_execution ( CancelExecutionRequest {
@@ -3116,25 +3109,23 @@ async fn cancellation_driver_finishes_running_cancellable_workflow_as_cancelled(
31163109 ) ;
31173110
31183111 // The driver drives it to Finished(Cancelled) without the 100s sleep ever expiring.
3119- let mut finished_kind = None ;
3120- for _ in 0 ..100 {
3112+ let finished_kind = loop {
31213113 let status = server. get_status_summary_grpc ( & exec_id) . await ;
31223114 if let Some ( Status :: Finished ( finished) ) = status
31233115 . current_status
31243116 . as_ref ( )
31253117 . and_then ( |status| status. status . as_ref ( ) )
31263118 {
3127- finished_kind = Some (
3119+ break Some (
31283120 finished
31293121 . result_kind
31303122 . as_ref ( )
31313123 . and_then ( |rk| rk. value )
31323124 . expect ( "finished must carry a result kind" ) ,
31333125 ) ;
3134- break ;
31353126 }
31363127 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
3137- }
3128+ } ;
31383129 assert_eq ! (
31393130 finished_kind,
31403131 Some ( grpc:: grpc_gen:: result_kind:: Value :: ExecutionFailureKind (
@@ -4882,25 +4873,21 @@ async fn activity_exec_stream_logs() {
48824873 let body: Value = resp. json ( ) . await . unwrap ( ) ;
48834874 assert_eq ! ( body, json!( { "ok" : null } ) ) ;
48844875
4885- let stderr_entries = tokio:: time:: timeout ( Duration :: from_secs ( 5 ) , async {
4886- loop {
4887- let logs = server. get_logs ( & exec_id) . await ;
4888- debug ! ( "Fetched logs: {logs:?}" ) ;
4889- let stderr_entries: Vec < Value > = logs
4890- . as_array ( )
4891- . expect ( "logs must be an array" )
4892- . iter ( )
4893- . filter ( |entry| entry[ "type" ] == "stream" && entry[ "stream_type" ] == "stderr" )
4894- . cloned ( )
4895- . collect ( ) ;
4896- if stderr_entries. len ( ) >= 2 {
4897- break stderr_entries;
4898- }
4899- tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
4876+ let stderr_entries = loop {
4877+ let logs = server. get_logs ( & exec_id, 2 ) . await ;
4878+ debug ! ( "Fetched logs: {logs:?}" ) ;
4879+ let stderr_entries: Vec < Value > = logs
4880+ . as_array ( )
4881+ . expect ( "logs must be an array" )
4882+ . iter ( )
4883+ . filter ( |entry| entry[ "type" ] == "stream" && entry[ "stream_type" ] == "stderr" )
4884+ . cloned ( )
4885+ . collect ( ) ;
4886+ if stderr_entries. len ( ) == 2 {
4887+ break stderr_entries;
49004888 }
4901- } )
4902- . await
4903- . expect ( "timed out waiting for stderr stream entries" ) ;
4889+ tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
4890+ } ;
49044891
49054892 // Streaming must produce 2 separate stderr entries (one per echo).
49064893 assert_eq ! (
0 commit comments