Welcome to mirror list, hosted at ThFree Co, Russian Federation.

click_house_spec.rb « views « peek « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7cecbaac883606cdfe23cf20529f924d96c4188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Peek::Views::ClickHouse, :click_house, :request_store, feature_category: :database do
  before do
    allow(::Gitlab::PerformanceBar).to receive(:enabled_for_request?).and_return(true)
  end

  describe '#results' do
    let(:results) { described_class.new.results }

    it 'includes performance details' do
      ::Gitlab::SafeRequestStore.clear!

      data = ClickHouse::Client.select('SELECT 1 AS value', :main)
      ClickHouse::Client.execute('INSERT INTO events (id) VALUES (1)', :main)

      Tempfile.open(['test', '.csv.gz']) do |f|
        File.binwrite(f.path, ActiveSupport::Gzip.compress("id\n10\n20"))

        ClickHouse::Client.insert_csv('INSERT INTO events (id) FORMAT CSV', File.open(f.path), :main)
      end

      expect(data).to eq([{ 'value' => 1 }])

      expect(results[:calls]).to eq(3)
      expect(results[:duration]).to be_kind_of(String)

      expect(results[:details]).to match_array([
        a_hash_including({
          sql: 'SELECT 1 AS value',
          database: 'database: main'
        }),
        a_hash_including({
          sql: 'INSERT INTO events (id) VALUES (1)',
          database: 'database: main'
        }),
        a_hash_including({
          sql: 'INSERT INTO events (id) FORMAT CSV',
          database: 'database: main'
        })
      ])
    end
  end
end