summaryrefslogtreecommitdiff
path: root/spec/support/pg_stat_activity.rb
blob: f93fba08a19838fb9e1b967989778edc493999ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

RSpec.configure do |config|
  config.before do
    if Gitlab::Database.postgresql? && ENV['PG_STAT_WARNING_THRESHOLD']
      warning_threshold = ENV['PG_STAT_WARNING_THRESHOLD'].to_i
      results = ActiveRecord::Base.connection.execute('SELECT * FROM pg_stat_activity')
      ntuples = results.ntuples

      warn("pg_stat_activity count: #{ntuples}")

      if ntuples > warning_threshold
        results.each do |result|
          warn result.inspect
        end
      end
    end
  end
end