Debian Codegraph @

mysql-test/suite/perfschema/t/hostcache_ipv4_max_con.test

raw
1
2 #
3 # Tests for the performance_schema host_cache.
4 #
5 # Simulate failures from per user quotas:
6 # - reported in COUNT_MAX_USER_CONNECTION_ERRORS
7 # - reported in COUNT_MAX_USER_CONNECTION_PER_HOUR_ERRORS
8 # Simulate failures from server quotas:
9 # - reported in COUNT_MAX_CONNECTION_ERRORS
10
11 --source include/have_debug.inc
12
13 # Enforce a clean state
14 --source ../include/wait_for_pfs_thread_count.inc
15 --source ../include/hostcache_set_state.inc
16
17 select @@global.max_connections into @saved_max_connections;
18
19 create user 'quota'@'santa.claus.ipv4.example.com'
20 with max_connections_per_hour 3;
21 grant select on test.* to 'quota'@'santa.claus.ipv4.example.com';
22 grant usage on *.* to 'quota'@'santa.claus.ipv4.example.com';
23
24 connect (con1,"127.0.0.1",root,,test,$MASTER_MYPORT,);
25 select "Con1 is alive";
26 select current_user();
27 disconnect con1;
28
29 --connection default
30 set global debug= "+d,vio_peer_addr_fake_ipv4,getnameinfo_fake_ipv4,getaddrinfo_fake_good_ipv4";
31
32 connect (con2a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
33 select "Con2a is alive";
34 select current_user();
35 disconnect con2a;
36
37 --connection default
38 --source ../include/hostcache_dump.inc
39
40 connect (con2b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
41 select "Con2b is alive";
42 select current_user();
43 disconnect con2b;
44
45 --connection default
46 --source ../include/hostcache_dump.inc
47
48 connect (con2c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
49 select "Con2c is alive";
50 select current_user();
51 disconnect con2c;
52
53 --connection default
54 --source ../include/hostcache_dump.inc
55
56 --disable_query_log
57 --error ER_USER_LIMIT_REACHED
58 connect (con2d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
59 --enable_query_log
60
61 --connection default
62 --source ../include/hostcache_dump.inc
63
64 --disable_query_log
65 --error ER_USER_LIMIT_REACHED
66 connect (con2e,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
67 --enable_query_log
68
69 --connection default
70 --source ../include/hostcache_dump.inc
71
72 # Wait for all disconnects
73 --source ../include/wait_for_pfs_thread_count.inc
74
75 alter user 'quota'@'santa.claus.ipv4.example.com'
76 with max_connections_per_hour 0;
77 alter user 'quota'@'santa.claus.ipv4.example.com'
78 with max_user_connections 3;
79 flush user_resources;
80
81 connect (con3a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
82 select "Con7 is alive";
83 select current_user();
84
85 --connection default
86 --source ../include/hostcache_dump.inc
87
88 connect (con3b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
89 select "Con3b is alive";
90 select current_user();
91
92 --connection default
93 --source ../include/hostcache_dump.inc
94
95 connect (con3c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
96 select "Con3c is alive";
97 select current_user();
98
99 --connection default
100 --source ../include/hostcache_dump.inc
101
102 --disable_query_log
103 --error ER_USER_LIMIT_REACHED
104 connect (con3d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
105 --enable_query_log
106
107 --connection default
108 --source ../include/hostcache_dump.inc
109
110 --disable_query_log
111 --error ER_USER_LIMIT_REACHED
112 connect (con3e,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
113 --enable_query_log
114
115 --connection default
116 --source ../include/hostcache_dump.inc
117
118 disconnect con3a;
119 disconnect con3b;
120 disconnect con3c;
121
122 # Wait for all disconnects
123 --source ../include/wait_for_pfs_thread_count.inc
124
125 alter user 'quota'@'santa.claus.ipv4.example.com'
126 with max_user_connections 0;
127 flush user_resources;
128
129 set global max_user_connections = 3;
130
131 connect (con4a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
132 select "Con4a is alive";
133 select current_user();
134
135 --connection default
136 --source ../include/hostcache_dump.inc
137
138 connect (con4b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
139 select "Con4b is alive";
140 select current_user();
141
142 --connection default
143 --source ../include/hostcache_dump.inc
144
145 connect (con4c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
146 select "Con4c is alive";
147 select current_user();
148
149 --connection default
150 --source ../include/hostcache_dump.inc
151
152 --disable_query_log
153 --error ER_TOO_MANY_USER_CONNECTIONS
154 connect (con4d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
155 --enable_query_log
156
157 --connection default
158 --source ../include/hostcache_dump.inc
159
160 --disable_query_log
161 --error ER_TOO_MANY_USER_CONNECTIONS
162 connect (con4e,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
163 --enable_query_log
164
165 --connection default
166 --source ../include/hostcache_dump.inc
167
168 disconnect con4a;
169 disconnect con4b;
170 disconnect con4c;
171
172 # Wait for all disconnects
173 --source ../include/wait_for_pfs_thread_count.inc
174
175 set global max_user_connections = 0;
176 set global max_connections = 3;
177 flush user_resources;
178
179 connect (con5a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
180 select "Con4a is alive";
181 select current_user();
182
183 --connection default
184 --source ../include/hostcache_dump.inc
185
186 connect (con5b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
187 select "Con5b is alive";
188 select current_user();
189
190 --connection default
191 --source ../include/hostcache_dump.inc
192
193 # About error ER_CON_COUNT_ERROR:
194 # - this error is associated with SQLSTATE 08004,
195 # and returned from 2 places in the server code.
196 # - which path returns the error is not predictable,
197 # as it depends on the server load and thread scheduling
198 # - one path returns a SQLSTATE of 08004
199 # - another path returns no SQLSTATE at all,
200 # and then the client sets a default value of HY000 for SQLSTATE
201 #
202 # Testing for error ER_CON_COUNT_ERROR alone causes this to
203 # be printed in the result file:
204 # - ERROR 08004: Too many connections
205 # which in turn causes spurious test failures.
206 #
207 # To work around this, this scripts expect to see either
208 # the error number ER_CON_COUNT_ERROR (it always does)
209 # or the error number 9999 (it never does, this error does not exist).
210 # The exact error number and SQLSTATE is not printed in the result file,
211 # makig this test robust for both cases:
212 # - ERROR 08004: Too many connections
213 # - ERROR HY000: Too many connections
214
215 --disable_query_log
216 --error ER_CON_COUNT_ERROR, 9999
217 connect (con5c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
218 --enable_query_log
219
220 --connection default
221 --source ../include/hostcache_dump.inc
222
223 --disable_query_log
224 --error ER_CON_COUNT_ERROR, 9999
225 connect (con5d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
226 --enable_query_log
227
228 --connection default
229 --source ../include/hostcache_dump.inc
230
231 disconnect con5a;
232 disconnect con5b;
233
234 # Wait for all disconnects
235 --source ../include/wait_for_pfs_thread_count.inc
236
237 set global max_connections = @saved_max_connections;
238
239 # revoke all privileges on test.* from 'quota'@'santa.claus.ipv4.example.com';
240 drop user 'quota'@'santa.claus.ipv4.example.com';
241
242 set global debug= default;
243