debian-mirror-gitlab/spec/lib/peek/views/redis_detailed_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Peek::Views::RedisDetailed, :request_store do
2019-10-12 21:52:04 +05:30
subject { described_class.new }
2019-09-30 21:07:59 +05:30
using RSpec::Parameterized::TableSyntax
2022-10-11 01:57:18 +05:30
where(:commands, :expected) do
[[:auth, 'test']] | 'auth <redacted>'
[[:set, 'key', 'value']] | 'set key <redacted>'
[[:set, 'bad']] | 'set bad'
[[:hmset, 'key1', 'value1', 'key2', 'value2']] | 'hmset key1 <redacted>'
[[:get, 'key']] | 'get key'
[[:get, 'key1'], [:get, 'key2']] | 'get key1, get key2'
[[:set, 'key1', 'value'], [:set, 'key2', 'value']] | 'set key1 <redacted>, set key2 <redacted>'
2019-09-30 21:07:59 +05:30
end
with_them do
2019-10-12 21:52:04 +05:30
it 'scrubs Redis commands' do
2022-10-11 01:57:18 +05:30
Gitlab::Instrumentation::Redis::SharedState.detail_store << { commands: commands, duration: 1.second }
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
expect(subject.results[:details].count).to eq(1)
expect(subject.results[:details].first)
2019-12-04 20:38:33 +05:30
.to include({
cmd: expected,
duration: 1000
})
2019-09-30 21:07:59 +05:30
end
end
2019-10-12 21:52:04 +05:30
it 'returns aggregated results' do
2022-10-11 01:57:18 +05:30
Gitlab::Instrumentation::Redis::Cache.detail_store << { commands: [[:get, 'test']], duration: 0.001 }
Gitlab::Instrumentation::Redis::Cache.detail_store << { commands: [[:get, 'test']], duration: 1.second }
Gitlab::Instrumentation::Redis::SharedState.detail_store << { commands: [[:get, 'test']], duration: 1.second }
2019-10-12 21:52:04 +05:30
2020-06-23 00:09:42 +05:30
expect(subject.results[:calls]).to eq(3)
expect(subject.results[:duration]).to eq('2001.00ms')
expect(subject.results[:details].count).to eq(3)
2019-10-12 21:52:04 +05:30
end
2019-09-30 21:07:59 +05:30
end