|
188 | 188 | end
|
189 | 189 | end
|
190 | 190 |
|
| 191 | + describe "Checkout failure limit" do |
| 192 | + context "when no checkout failure limit is set" do |
| 193 | + before do |
| 194 | + new_configs = processes.pgcat.current_config |
| 195 | + new_configs["general"]["connect_timeout"] = 200 |
| 196 | + new_configs["pools"]["sharded_db"]["users"]["0"]["pool_size"] = 1 |
| 197 | + processes.pgcat.update_config(new_configs) |
| 198 | + processes.pgcat.reload_config |
| 199 | + sleep 0.5 |
| 200 | + end |
| 201 | + |
| 202 | + it "does not disconnect client" do |
| 203 | + Array.new(5) do |
| 204 | + Thread.new do |
| 205 | + conn = PG::connect(processes.pgcat.connection_string("sharded_db", "sharding_user")) |
| 206 | + for i in 0..4 |
| 207 | + begin |
| 208 | + conn.async_exec("SELECT pg_sleep(0.5);") |
| 209 | + expect(conn.status).to eq(PG::CONNECTION_OK) |
| 210 | + rescue PG::SystemError |
| 211 | + expect(conn.status).to eq(PG::CONNECTION_OK) |
| 212 | + end |
| 213 | + end |
| 214 | + conn.close |
| 215 | + end |
| 216 | + end.each(&:join) |
| 217 | + end |
| 218 | + end |
| 219 | + |
| 220 | + context "when checkout failure limit is set high" do |
| 221 | + before do |
| 222 | + new_configs = processes.pgcat.current_config |
| 223 | + new_configs["general"]["connect_timeout"] = 200 |
| 224 | + new_configs["pools"]["sharded_db"]["users"]["0"]["pool_size"] = 1 |
| 225 | + new_configs["pools"]["sharded_db"]["checkout_failure_limit"] = 10000 |
| 226 | + processes.pgcat.update_config(new_configs) |
| 227 | + processes.pgcat.reload_config |
| 228 | + sleep 0.5 |
| 229 | + end |
| 230 | + |
| 231 | + it "does not disconnect client" do |
| 232 | + Array.new(5) do |
| 233 | + Thread.new do |
| 234 | + conn = PG::connect(processes.pgcat.connection_string("sharded_db", "sharding_user")) |
| 235 | + for i in 0..4 |
| 236 | + begin |
| 237 | + conn.async_exec("SELECT pg_sleep(0.5);") |
| 238 | + expect(conn.status).to eq(PG::CONNECTION_OK) |
| 239 | + rescue PG::SystemError |
| 240 | + expect(conn.status).to eq(PG::CONNECTION_OK) |
| 241 | + end |
| 242 | + end |
| 243 | + conn.close |
| 244 | + end |
| 245 | + end.each(&:join) |
| 246 | + end |
| 247 | + end |
| 248 | + |
| 249 | + context "when checkout failure limit is set low" do |
| 250 | + before do |
| 251 | + new_configs = processes.pgcat.current_config |
| 252 | + new_configs["general"]["connect_timeout"] = 200 |
| 253 | + new_configs["pools"]["sharded_db"]["users"]["0"]["pool_size"] = 1 |
| 254 | + new_configs["pools"]["sharded_db"]["checkout_failure_limit"] = 2 |
| 255 | + processes.pgcat.update_config(new_configs) |
| 256 | + processes.pgcat.reload_config |
| 257 | + sleep 0.5 |
| 258 | + end |
| 259 | + |
| 260 | + it "disconnects client after reaching limit" do |
| 261 | + Array.new(5) do |
| 262 | + Thread.new do |
| 263 | + conn = PG::connect(processes.pgcat.connection_string("sharded_db", "sharding_user")) |
| 264 | + checkout_failure_count = 0 |
| 265 | + for i in 0..4 |
| 266 | + begin |
| 267 | + conn.async_exec("SELECT pg_sleep(1);") |
| 268 | + expect(conn.status).to eq(PG::CONNECTION_OK) |
| 269 | + rescue PG::SystemError |
| 270 | + checkout_failure_count += 1 |
| 271 | + expect(conn.status).to eq(PG::CONNECTION_OK) |
| 272 | + rescue PG::ConnectionBad |
| 273 | + expect(checkout_failure_count).to eq(2) |
| 274 | + expect(conn.status).to eq(PG::CONNECTION_BAD) |
| 275 | + break |
| 276 | + end |
| 277 | + end |
| 278 | + conn.close |
| 279 | + end |
| 280 | + end.each(&:join) |
| 281 | + puts processes.pgcat.logs |
| 282 | + |
| 283 | + end |
| 284 | + end |
| 285 | + end |
| 286 | + |
191 | 287 | describe "Server version reporting" do
|
192 | 288 | it "reports correct version for normal and admin databases" do
|
193 | 289 | server_conn = PG::connect(processes.pgcat.connection_string("sharded_db", "sharding_user"))
|
|
0 commit comments