spec_helper.rb 738 B

12345678910111213141516171819202122232425262728
  1. # frozen_string_literal: true
  2. require 'pg'
  3. require_relative 'helpers/pgcat_helper'
  4. QUERY_COUNT = 300
  5. MARGIN_OF_ERROR = 0.35
  6. def with_captured_stdout_stderr
  7. sout = STDOUT.clone
  8. serr = STDERR.clone
  9. STDOUT.reopen("/tmp/out.txt", "w+")
  10. STDERR.reopen("/tmp/err.txt", "w+")
  11. STDOUT.sync = true
  12. STDERR.sync = true
  13. yield
  14. return File.read('/tmp/out.txt'), File.read('/tmp/err.txt')
  15. ensure
  16. STDOUT.reopen(sout)
  17. STDERR.reopen(serr)
  18. end
  19. def clients_connected_to_pool(pool_index: 0, processes:)
  20. admin_conn = PG::connect(processes.pgcat.admin_connection_string)
  21. results = admin_conn.async_exec("SHOW POOLS")[pool_index]
  22. admin_conn.close
  23. results['cl_idle'].to_i + results['cl_active'].to_i + results['cl_waiting'].to_i
  24. end