Fix maxwait metric (#183)

Max wait was being reported as 0 after #159

This PR fixes that and adds test
This commit is contained in:
Mostafa Abdelraouf
2022-10-05 21:41:09 -05:00
committed by GitHub
parent 7987c5ffad
commit 3d33ccf4b0
4 changed files with 55 additions and 23 deletions

View File

@@ -208,6 +208,28 @@ describe "Admin" do
threads.map(&:join)
connections.map(&:close)
end
it "show correct max_wait" do
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 pg_sleep(1.5)") }
end
sleep(2.5) # Allow time for stats to update
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
results = admin_conn.async_exec("SHOW POOLS")[0]
expect(results["maxwait"]).to eq("1")
expect(results["maxwait_us"].to_i).to be_within(100_000).of(500_000)
sleep(4.5) # Allow time for stats to update
results = admin_conn.async_exec("SHOW POOLS")[0]
expect(results["maxwait"]).to eq("0")
threads.map(&:join)
connections.map(&:close)
end
end
end