@@ -970,10 +970,7 @@ session_expiry(Config) ->
970970 ok = emqtt :disconnect (C ),
971971
972972 ? assertEqual (2 , rpc (Config , rabbit_amqqueue , count , [])),
973- timer :sleep (timer :seconds (Seconds ) + 100 ),
974- % % On a slow machine, this test might fail. Let's consider
975- % % the expiry on a longer time window
976- ? awaitMatch (0 , rpc (Config , rabbit_amqqueue , count , []), 15_000 , 1000 ),
973+ ? awaitMatch (0 , rpc (Config , rabbit_amqqueue , count , []), 15_000 , 1000 ),
977974
978975 ok = rpc (Config , application , set_env , [App , Par , DefaultVal ]).
979976
@@ -1235,11 +1232,16 @@ rabbit_mqtt_qos0_queue_kill_node(Config) ->
12351232 ok = emqtt :publish (Pub , Topic1 , <<" m0" >>, qos0 ),
12361233 ok = expect_publishes (Sub0 , Topic1 , [<<" m0" >>]),
12371234
1235+ [Node0 | _ ] = rabbit_ct_broker_helpers :get_node_configs (Config , nodename ),
12381236 process_flag (trap_exit , true ),
12391237 ok = rabbit_ct_broker_helpers :kill_node (Config , 0 ),
12401238 ok = await_exit (Sub0 ),
1241- % % Wait to run rabbit_amqqueue:on_node_down/1 on both live nodes.
1242- timer :sleep (500 ),
1239+ % % Wait for the live nodes to detect that node 0 has gone down,
1240+ % % otherwise the subsequent reconnect on node 1 may briefly stall
1241+ % % on cluster lookups that try to reach node 0.
1242+ rabbit_ct_helpers :await_condition (
1243+ fun () -> not lists :member (Node0 , rpc (Config , 1 , rabbit_nodes , list_running , [])) end ,
1244+ 10_000 ),
12431245 % % Re-connect to a live node with same MQTT client ID.
12441246 Sub1 = connect (SubscriberId , Config , 1 , []),
12451247 {ok , _ , [0 ]} = emqtt :subscribe (Sub1 , Topic2 , qos0 ),
@@ -1390,12 +1392,15 @@ maintenance(Config) ->
13901392 C1b = connect (<<" client-1b" >>, Config , 1 , []),
13911393 ClientsNode1 = [C1a , C1b ],
13921394
1393- timer :sleep (500 ),
1395+ rabbit_ct_helpers :await_condition (
1396+ fun () -> length (all_connection_pids (Config )) =:= 3 end ,
1397+ 10_000 ),
13941398
13951399 ok = drain_node (Config , 2 ),
13961400 ok = revive_node (Config , 2 ),
1397- timer :sleep (500 ),
1398- [? assert (erlang :is_process_alive (C )) || C <- [C0 , C1a , C1b ]],
1401+ rabbit_ct_helpers :await_condition (
1402+ fun () -> lists :all (fun erlang :is_process_alive /1 , [C0 , C1a , C1b ]) end ,
1403+ 10_000 ),
13991404
14001405 process_flag (trap_exit , true ),
14011406 ok = drain_node (Config , 1 ),
@@ -1544,8 +1549,10 @@ block(Config) ->
15441549 {ok , _ } = emqtt :publish (C , Topic , <<" Not blocked yet" >>, [{qos , 1 }]),
15451550
15461551 ok = rpc (Config , vm_memory_monitor , set_vm_memory_high_watermark , [0 ]),
1547- % % Let it block
1548- timer :sleep (100 ),
1552+ rabbit_ct_helpers :await_condition (fun () ->
1553+ Alarms = rpc (Config , rabbit_alarm , get_alarms , []),
1554+ lists :any (fun ({{resource_limit , memory , _ }, _ }) -> true ; (_ ) -> false end , Alarms )
1555+ end , 10_000 ),
15491556
15501557 % % Blocked, but still will publish when unblocked
15511558 puback_timeout = publish_qos1_timeout (C , Topic , <<" Now blocked" >>, 1000 ),
@@ -1575,8 +1582,10 @@ block_only_publisher(Config) ->
15751582 ok = expect_publishes (PubSub , Topic , [<<" from Pub" >>, <<" from PubSub" >>]),
15761583
15771584 ok = rpc (Config , vm_memory_monitor , set_vm_memory_high_watermark , [0 ]),
1578- % % Let it block
1579- timer :sleep (100 ),
1585+ rabbit_ct_helpers :await_condition (fun () ->
1586+ Alarms = rpc (Config , rabbit_alarm , get_alarms , []),
1587+ lists :any (fun ({{resource_limit , memory , _ }, _ }) -> true ; (_ ) -> false end , Alarms )
1588+ end , 10_000 ),
15801589
15811590 % % We expect that the publishing connections are blocked.
15821591 [? assertEqual ({error , ack_timeout }, emqtt :ping (Pid )) || Pid <- [Pub , PubSub ]],
@@ -1594,8 +1603,10 @@ block_only_publisher(Config) ->
15941603 ? assertEqual (pong , emqtt :ping (Sub )),
15951604
15961605 rpc (Config , vm_memory_monitor , set_vm_memory_high_watermark , [0.6 ]),
1597- % % Let it unblock
1598- timer :sleep (100 ),
1606+ rabbit_ct_helpers :await_condition (fun () ->
1607+ Alarms = rpc (Config , rabbit_alarm , get_alarms , []),
1608+ not lists :any (fun ({{resource_limit , memory , _ }, _ }) -> true ; (_ ) -> false end , Alarms )
1609+ end , 10_000 ),
15991610
16001611 % % All connections are unblocked.
16011612 [? assertEqual (pong , emqtt :ping (Pid )) || Pid <- [Con , Sub , Pub , PubSub ]],
0 commit comments