Skip to content

Commit

Permalink
Add tests for client connection counters
Browse files Browse the repository at this point in the history
  • Loading branch information
magec committed Mar 28, 2023
1 parent 761a2fa commit e279723
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/ruby/admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@
end
end

context "clients connects and disconnect normally" do
let(:processes) { Helpers::Pgcat.single_instance_setup("sharded_db", 2) }

it 'shows the number same number of clients before and after' do
clients_before = clients_connected_to_pool(processes: processes)
threads = []
connections = Array.new(4) { PG::connect("#{pgcat_conn_str}?application_name=one_query") }
connections.each do |c|
threads << Thread.new { c.async_exec("SELECT 1") }
end
clients_between = clients_connected_to_pool(processes: processes)
expect(clients_before).not_to eq(clients_between)
connections.each(&:close)
clients_after = clients_connected_to_pool(processes: processes)
expect(clients_before).to eq(clients_after)
end
end

context "clients overwhelm server pools" do
let(:processes) { Helpers::Pgcat.single_instance_setup("sharded_db", 2) }

Expand Down
Binary file added tests/ruby/capture
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/ruby/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ def with_captured_stdout_stderr
STDOUT.reopen(sout)
STDERR.reopen(serr)
end

def clients_connected_to_pool(pool_index: 0, processes:)
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
results = admin_conn.async_exec("SHOW POOLS")[pool_index]
admin_conn.close
results['cl_idle'].to_i + results['cl_active'].to_i + results['cl_waiting'].to_i
end

0 comments on commit e279723

Please sign in to comment.