|
179 | 179 | context "clients connects and disconnect normally" do
|
180 | 180 | let(:processes) { Helpers::Pgcat.single_instance_setup("sharded_db", 2) }
|
181 | 181 |
|
182 |
| - it 'shows the number same number of clients before and after' do |
| 182 | + it 'shows the same number of clients before and after' do |
183 | 183 | clients_before = clients_connected_to_pool(processes: processes)
|
184 | 184 | threads = []
|
185 | 185 | connections = Array.new(4) { PG::connect("#{pgcat_conn_str}?application_name=one_query") }
|
|
194 | 194 | end
|
195 | 195 | end
|
196 | 196 |
|
| 197 | + context "clients connects and disconnect abruptly" do |
| 198 | + let(:processes) { Helpers::Pgcat.single_instance_setup("sharded_db", 10) } |
| 199 | + |
| 200 | + it 'shows the same number of clients before and after' do |
| 201 | + threads = [] |
| 202 | + connections = Array.new(2) { PG::connect("#{pgcat_conn_str}?application_name=one_query") } |
| 203 | + connections.each do |c| |
| 204 | + threads << Thread.new { c.async_exec("SELECT 1") } |
| 205 | + end |
| 206 | + clients_before = clients_connected_to_pool(processes: processes) |
| 207 | + random_string = (0...8).map { (65 + rand(26)).chr }.join |
| 208 | + connection_string = "#{pgcat_conn_str}?application_name=#{random_string}" |
| 209 | + faulty_client = Process.spawn("psql -Atx #{connection_string} >/dev/null") |
| 210 | + sleep(1) |
| 211 | + # psql starts two processes, we only know the pid of the parent, this |
| 212 | + # ensure both are killed |
| 213 | + `pkill -9 -f '#{random_string}'` |
| 214 | + Process.wait(faulty_client) |
| 215 | + clients_after = clients_connected_to_pool(processes: processes) |
| 216 | + expect(clients_before).to eq(clients_after) |
| 217 | + end |
| 218 | + end |
| 219 | + |
197 | 220 | context "clients overwhelm server pools" do
|
198 | 221 | let(:processes) { Helpers::Pgcat.single_instance_setup("sharded_db", 2) }
|
199 | 222 |
|
|
0 commit comments