@@ -51,7 +51,9 @@ all_tests() -> [
51
51
protocol_listener_test ,
52
52
port_listener_test ,
53
53
certificate_expiration_test ,
54
- is_in_service_test
54
+ is_in_service_test ,
55
+ below_node_connection_limit_test ,
56
+ ready_to_serve_clients_test
55
57
].
56
58
57
59
% % -------------------------------------------------------------------
@@ -470,8 +472,66 @@ is_in_service_test(Config) ->
470
472
471
473
passed .
472
474
475
+ below_node_connection_limit_test (Config ) ->
476
+ Path = " /health/checks/below-node-connection-limit" ,
477
+ Check0 = http_get (Config , Path , ? OK ),
478
+ ? assertEqual (<<" ok" >>, maps :get (status , Check0 )),
479
+ ? assertEqual (0 , maps :get (connections , Check0 )),
480
+ ? assertEqual (<<" infinity" >>, maps :get (limit , Check0 )),
481
+
482
+ % % Set the connection limit low and open 'limit' connections.
483
+ Limit = 10 ,
484
+ rabbit_ct_broker_helpers :rpc (
485
+ Config , 0 , application , set_env , [rabbit , connection_max , Limit ]),
486
+ Connections = [rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ) || _ <- lists :seq (1 , Limit )],
487
+ true = lists :all (fun (E ) -> is_pid (E ) end , Connections ),
488
+ {error , not_allowed } = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ),
489
+
490
+ Body0 = http_get_failed (Config , Path ),
491
+ ? assertEqual (<<" failed" >>, maps :get (<<" status" >>, Body0 )),
492
+ ? assertEqual (10 , maps :get (<<" limit" >>, Body0 )),
493
+ ? assertEqual (10 , maps :get (<<" connections" >>, Body0 )),
494
+
495
+ % % Clean up the connections and reset the limit.
496
+ [catch rabbit_ct_client_helpers :close_connection (C ) || C <- Connections ],
497
+ rabbit_ct_broker_helpers :rpc (
498
+ Config , 0 , application , set_env , [rabbit , connection_max , infinity ]),
499
+
500
+ passed .
501
+
502
+ ready_to_serve_clients_test (Config ) ->
503
+ Path = " /health/checks/ready-to-serve-clients" ,
504
+ Check0 = http_get (Config , Path , ? OK ),
505
+ ? assertEqual (<<" ok" >>, maps :get (status , Check0 )),
506
+
507
+ true = rabbit_ct_broker_helpers :mark_as_being_drained (Config , 0 ),
508
+ Body0 = http_get_failed (Config , Path ),
509
+ ? assertEqual (<<" failed" >>, maps :get (<<" status" >>, Body0 )),
510
+ true = rabbit_ct_broker_helpers :unmark_as_being_drained (Config , 0 ),
511
+
512
+ % % Set the connection limit low and open 'limit' connections.
513
+ Limit = 10 ,
514
+ rabbit_ct_broker_helpers :rpc (
515
+ Config , 0 , application , set_env , [rabbit , connection_max , Limit ]),
516
+ Connections = [rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ) || _ <- lists :seq (1 , Limit )],
517
+ true = lists :all (fun (E ) -> is_pid (E ) end , Connections ),
518
+ {error , not_allowed } = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ),
519
+
520
+ Body1 = http_get_failed (Config , Path ),
521
+ ? assertEqual (<<" failed" >>, maps :get (<<" status" >>, Body1 )),
522
+ ? assertEqual (10 , maps :get (<<" limit" >>, Body1 )),
523
+ ? assertEqual (10 , maps :get (<<" connections" >>, Body1 )),
524
+
525
+ % % Clean up the connections and reset the limit.
526
+ [catch rabbit_ct_client_helpers :close_connection (C ) || C <- Connections ],
527
+ rabbit_ct_broker_helpers :rpc (
528
+ Config , 0 , application , set_env , [rabbit , connection_max , infinity ]),
529
+
530
+ passed .
531
+
473
532
http_get_failed (Config , Path ) ->
474
533
{ok , {{_ , Code , _ }, _ , ResBody }} = req (Config , get , Path , [auth_header (" guest" , " guest" )]),
534
+ ct :pal (" GET ~s : ~w ~w " , [Path , Code , ResBody ]),
475
535
? assertEqual (Code , ? HEALTH_CHECK_FAILURE_STATUS ),
476
536
rabbit_json :decode (rabbit_data_coercion :to_binary (ResBody )).
477
537
0 commit comments