15
15
16
16
all () ->
17
17
[
18
- {group , parallel_tests }
18
+ {group , limit_tests }
19
19
].
20
20
21
21
groups () ->
22
22
[
23
- {parallel_tests , [parallel ], [
24
- node_connection_limit ,
25
- vhost_limit
26
- ]}
23
+ {limit_tests , [], [
24
+ node_connection_limit ,
25
+ vhost_limit ,
26
+ node_channel_limit
27
+ ]}
27
28
].
28
29
29
30
suite () ->
@@ -60,9 +61,15 @@ init_per_testcase(Testcase, Config) ->
60
61
rabbit_ct_helpers :testcase_started (Config , Testcase ).
61
62
62
63
end_per_testcase (vhost_limit = Testcase , Config ) ->
64
+ set_node_limit (Config , vhost_max , infinity ),
65
+ set_node_limit (Config , channel_max_per_node , 0 ),
66
+ set_node_limit (Config , connection_max , infinity ),
63
67
[rabbit_ct_broker_helpers :delete_vhost (Config , integer_to_binary (I )) || I <- lists :seq (1 ,4 )],
64
68
rabbit_ct_helpers :testcase_finished (Config , Testcase );
65
69
end_per_testcase (Testcase , Config ) ->
70
+ set_node_limit (Config , vhost_max , infinity ),
71
+ set_node_limit (Config , channel_max_per_node , 0 ),
72
+ set_node_limit (Config , connection_max , infinity ),
66
73
rabbit_ct_helpers :testcase_finished (Config , Testcase ).
67
74
68
75
% % -------------------------------------------------------------------
@@ -71,7 +78,7 @@ end_per_testcase(Testcase, Config) ->
71
78
72
79
node_connection_limit (Config ) ->
73
80
% % Set limit to 0, don't accept any connections
74
- set_node_limit (Config , 0 ),
81
+ set_node_limit (Config , connection_max , 0 ),
75
82
{error , not_allowed } = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ),
76
83
77
84
% % Set limit to 5, accept 5 connections
@@ -80,47 +87,88 @@ node_connection_limit(Config) ->
80
87
{error , not_allowed } = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ),
81
88
close_all_connections (Connections ),
82
89
83
- set_node_limit (Config , infinity ),
90
+ set_node_limit (Config , connection_max , infinity ),
84
91
C = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ),
85
92
true = is_pid (C ),
86
93
close_all_connections ([C ]),
87
94
ok .
88
95
89
96
vhost_limit (Config ) ->
90
- set_vhost_limit (Config , 0 ),
97
+ set_node_limit (Config , vhost_max , 0 ),
91
98
{'EXIT' ,{vhost_limit_exceeded , _ }} = rabbit_ct_broker_helpers :add_vhost (Config , <<" foo" >>),
92
99
93
- set_vhost_limit (Config , 5 ),
100
+ set_node_limit (Config , vhost_max , 5 ),
94
101
[ok = rabbit_ct_broker_helpers :add_vhost (Config , integer_to_binary (I )) || I <- lists :seq (1 ,4 )],
95
102
{'EXIT' ,{vhost_limit_exceeded , _ }} = rabbit_ct_broker_helpers :add_vhost (Config , <<" 5" >>),
96
103
[rabbit_ct_broker_helpers :delete_vhost (Config , integer_to_binary (I )) || I <- lists :seq (1 ,4 )],
97
104
98
- set_vhost_limit (Config , infinity ),
105
+ set_node_limit (Config , vhost_max , infinity ),
99
106
[ok = rabbit_ct_broker_helpers :add_vhost (Config , integer_to_binary (I )) || I <- lists :seq (1 ,4 )],
100
107
ok = rabbit_ct_broker_helpers :add_vhost (Config , <<" 5" >>),
101
108
[rabbit_ct_broker_helpers :delete_vhost (Config , integer_to_binary (I )) || I <- lists :seq (1 ,5 )],
102
109
ok .
103
110
111
+ node_channel_limit (Config ) ->
112
+ set_node_limit (Config , channel_max_per_node , 5 ),
113
+
114
+ VHost = <<" foobar" >>,
115
+ User = <<" guest" >>,
116
+ ok = rabbit_ct_broker_helpers :add_vhost (Config , VHost ),
117
+ ok = rabbit_ct_broker_helpers :set_full_permissions (Config , User , VHost ),
118
+ Conn1 = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 , VHost ),
119
+ Conn2 = rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 , VHost ),
120
+
121
+ lists :foreach (fun (N ) when (N band 1 ) == 1 -> {ok , _ } = open_channel (Conn1 );
122
+ (_ ) -> {ok ,_ } = open_channel (Conn2 )
123
+ end , lists :seq (1 , 5 )),
124
+
125
+ 5 = count_channels_per_node (Config ),
126
+ % % In total 5 channels are open on this node, so a new one, regardless of
127
+ % % connection, will not be allowed. It will terminate the connection with
128
+ % % its channels too. So
129
+ {error , not_allowed_crash } = open_channel (Conn2 ),
130
+ 3 = count_channels_per_node (Config ),
131
+ % % As the connection is dead, so are the 2 channels, so we should be able to
132
+ % % create 2 more on Conn1
133
+ {ok , _ } = open_channel (Conn1 ),
134
+ {ok , _ } = open_channel (Conn1 ),
135
+ % % But not a third
136
+ {error , not_allowed_crash } = open_channel (Conn1 ),
137
+
138
+ % % Now all connections are closed, so there should be 0 open connections
139
+ 0 = count_channels_per_node (Config ),
140
+ ok .
104
141
105
142
% % -------------------------------------------------------------------
106
143
% % Implementation
107
144
% % -------------------------------------------------------------------
108
145
109
146
open_connections_to_limit (Config , Limit ) ->
110
- set_node_limit (Config , Limit ),
147
+ set_node_limit (Config , connection_max , Limit ),
111
148
Connections = [rabbit_ct_client_helpers :open_unmanaged_connection (Config , 0 ) || _ <- lists :seq (1 ,Limit )],
112
149
true = lists :all (fun (E ) -> is_pid (E ) end , Connections ),
113
150
Connections .
114
151
115
152
close_all_connections (Connections ) ->
116
153
[rabbit_ct_client_helpers :close_connection (C ) || C <- Connections ].
117
154
118
- set_node_limit (Config , Limit ) ->
119
- rabbit_ct_broker_helpers :rpc (Config , 0 ,
120
- application ,
121
- set_env , [rabbit , connection_max , Limit ]).
122
-
123
- set_vhost_limit (Config , Limit ) ->
155
+ set_node_limit (Config , Type , Limit ) ->
124
156
rabbit_ct_broker_helpers :rpc (Config , 0 ,
125
157
application ,
126
- set_env , [rabbit , vhost_max , Limit ]).
158
+ set_env , [rabbit , Type , Limit ]).
159
+
160
+ open_channel (Conn ) when is_pid (Conn ) ->
161
+ try amqp_connection :open_channel (Conn ) of
162
+ {ok , Ch } -> {ok , Ch };
163
+ {error , _ } ->
164
+ {error , not_allowed }
165
+ catch
166
+ _ :_Error -> {error , not_allowed_crash }
167
+ end .
168
+
169
+ count_channels_per_node (Config ) ->
170
+ NodeConfig = rabbit_ct_broker_helpers :get_node_config (Config , 0 ),
171
+ length (rabbit_ct_broker_helpers :rpc (Config , 0 ,
172
+ rabbit_channel_tracking ,
173
+ list_on_node ,
174
+ [? config (nodename , NodeConfig )])).
0 commit comments