@@ -189,7 +189,7 @@ do_not_accept_0_hold_value(Config) ->
189189send_specific_hold (Config , HoldValue ) ->
190190 {Server , Path , Client } = get_fusco_connection (Config ),
191191
192- Rid = random :uniform (1000000 ),
192+ Rid = rand :uniform (1000000 ),
193193 Body0 = escalus_bosh :session_creation_body (2 , <<" 1.0" >>, <<" en" >>, Rid , Server , nil ),
194194 # xmlel {attrs = Attrs0 } = Body0 ,
195195 Attrs = lists :keyreplace (<<" hold" >>, 1 , Attrs0 , {<<" hold" >>, HoldValue }),
@@ -379,7 +379,7 @@ cant_send_invalid_rid(Config) ->
379379
380380 escalus :assert (is_stream_end , escalus :wait_for_stanza (Carol )),
381381 escalus_client :wait_for_close (Config , Carol , timer :seconds (1 )),
382- true = wait_for_session_close (Sid , 10 )
382+ { ok , false } = wait_for_session_close (Sid )
383383
384384 end ).
385385
@@ -464,7 +464,7 @@ disconnect_inactive(Config) ->
464464 timer :sleep (2 * timer :seconds (? INACTIVITY )),
465465
466466 % % Assert Carol has been disconnected due to inactivity.
467- false = is_sesssion_alive (Sid ),
467+ false = is_session_alive (Sid ),
468468
469469 % % We don't need to close the session in escalus_bosh:stop/1
470470 escalus_client :kill_connection (Config , Carol )
@@ -486,7 +486,7 @@ connection_interrupted(Config) ->
486486
487487 % % Assert Carol has not been disconnected yet.
488488 timer :sleep (100 ),
489- true = is_sesssion_alive (Sid ),
489+ true = is_session_alive (Sid ),
490490
491491 % % Wait for disconnection because of inactivity timeout.
492492 % % Keep in mind this only works due to the max_wait also being lowered.
@@ -495,7 +495,7 @@ connection_interrupted(Config) ->
495495 timer :sleep (timer :seconds (? INACTIVITY ) + timer :seconds (? MAX_WAIT )),
496496
497497 % % Assert Carol has been disconnected due to inactivity.
498- false = is_sesssion_alive (Sid )
498+ false = is_session_alive (Sid )
499499
500500 end ).
501501
@@ -510,7 +510,7 @@ interrupt_long_poll_is_activity(ConfigIn) ->
510510 % % to Carol and one handler for Carol.
511511 Sid = get_bosh_sid (Carol ),
512512 {_ , _ , CarolSessionPid } = get_bosh_session (Sid ),
513- 1 = wait_for_handler (CarolSessionPid ),
513+ { ok , 1 } = wait_for_handler (CarolSessionPid ),
514514
515515 % % Send a message. A new connection should be established, and
516516 % % the existing long-poll connection should be closed.
@@ -523,8 +523,8 @@ interrupt_long_poll_is_activity(ConfigIn) ->
523523
524524 % % No disconnection should have occurred.
525525 escalus_assert :has_no_stanzas (Carol ),
526- true = is_sesssion_alive (Sid ),
527- 1 = wait_for_handler (CarolSessionPid )
526+ true = is_session_alive (Sid ),
527+ { ok , 1 } = wait_for_handler (CarolSessionPid )
528528
529529 end ).
530530
@@ -536,13 +536,13 @@ reply_on_pause(Config) ->
536536 set_keepalive (Carol , false ),
537537
538538 % % Sanity check - there should be one handler for Carol.
539- 1 = wait_for_handler (CarolSessionPid ),
539+ { ok , 1 } = wait_for_handler (CarolSessionPid ),
540540
541541 pause (Carol , 10 ),
542542
543543 % % There should be no handlers for Carol,
544544 % % but the session should be alive.
545- true = is_sesssion_alive (Sid ),
545+ true = is_session_alive (Sid ),
546546 0 = length (get_handlers (CarolSessionPid )),
547547 0 = get_bosh_requests (Carol )
548548
@@ -556,13 +556,13 @@ cant_pause_for_too_long(Config) ->
556556 set_keepalive (Carol , false ),
557557
558558 % % Sanity check - there should be one handler for Carol.
559- 1 = wait_for_handler (CarolSessionPid ),
559+ { ok , 1 } = wait_for_handler (CarolSessionPid ),
560560
561561 pause (Carol , 10000 ),
562562
563563 escalus :assert (is_stream_end , escalus :wait_for_stanza (Carol )),
564564 escalus_client :wait_for_close (Config , Carol , timer :seconds (1 )),
565- false = is_sesssion_alive (Sid )
565+ false = is_session_alive (Sid )
566566
567567 end ).
568568
@@ -575,7 +575,7 @@ pause_request_is_activity(Config) ->
575575 set_keepalive (Carol , false ),
576576
577577 % % Sanity check - there should be one handler for Carol.
578- 1 = wait_for_handler (CarolSessionPid ),
578+ { ok , 1 } = wait_for_handler (CarolSessionPid ),
579579
580580 % % Wait most of the allowed inactivity interval.
581581 timer :sleep (timer :seconds (? INACTIVITY - 1 )),
@@ -588,7 +588,7 @@ pause_request_is_activity(Config) ->
588588
589589 % % No disconnection should've occured.
590590 escalus_assert :has_no_stanzas (Carol ),
591- true = is_sesssion_alive (Sid )
591+ true = is_session_alive (Sid )
592592
593593 end ).
594594
@@ -618,7 +618,7 @@ reply_in_time(ConfigIn) ->
618618 Empty = escalus_bosh :empty_body (Rid , Sid ),
619619 bosh_send_raw (Carol , Empty ),
620620 timer :sleep (100 ),
621- 1 = wait_for_handler (CarolSessionPid ),
621+ { ok , 1 } = wait_for_handler (CarolSessionPid ),
622622
623623 timer :sleep (timer :seconds (Wait ) + 100 ),
624624
@@ -870,34 +870,24 @@ server_acks_opt() ->
870870 fun (V ) -> rpc (mim (), mod_bosh , set_server_acks , [V ]) end ,
871871 true }.
872872
873- is_sesssion_alive (Sid ) ->
873+ is_session_alive (Sid ) ->
874874 BoshSessions = get_bosh_sessions (),
875875 lists :keymember (Sid , 2 , BoshSessions ).
876876
877- wait_for_session_close (Sid , 0 ) ->
878- false == is_sesssion_alive (Sid );
879- wait_for_session_close (Sid , N ) ->
880- case is_sesssion_alive (Sid ) of
881- false ->
882- true ;
883- _ ->
884- timer :sleep (100 ),
885- wait_for_session_close (Sid , N - 1 )
886- end .
877+ wait_for_session_close (Sid ) ->
878+ mongoose_helper :wait_until (fun () -> is_session_alive (Sid ) end , false ,
879+ #{
880+ time_left => timer :seconds (10 ),
881+ time_sleep => timer :seconds (1 ),
882+ name => is_session_alive
883+ }).
887884
888885wait_for_handler (Pid ) ->
889- wait_for_handler (Pid , 10 ).
890-
891- wait_for_handler (Pid , 0 ) ->
892- length (get_handlers (Pid ));
893- wait_for_handler (Pid , N ) ->
894- case get_handlers (Pid ) of
895- [] ->
896- timer :sleep (50 ),
897- wait_for_handler (Pid , N - 1 );
898- L ->
899- length (L )
900- end .
886+ mongoose_helper :wait_until (fun () -> length (get_handlers (Pid )) end , 1 , #{
887+ time_left => timer :seconds (10 ),
888+ time_sleep => timer :seconds (1 ),
889+ name => get_handlers
890+ }).
901891
902892domain () ->
903893 ct :get_config ({hosts , mim , domain }).
0 commit comments