gitlab-org--gitlab-foss/spec/lib/peek/views/redis_detailed_spec.rb
Sean McGivern 23c1cfcc11 Return warnings for performance bar from backend
For each DetailedView subclass, we add a `warnings` array to:

1. The top-level response.
2. Each individual call under the `details` key.

We use the `.thresholds` hash on the DetailedView to determine what's a
warning. If that hash is empty (the default), then the warnings array
will always be empty.
2019-08-28 16:39:33 +01:00

39 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe Peek::Views::RedisDetailed, :request_store do
subject { described_class.new }
using RSpec::Parameterized::TableSyntax
where(:cmd, :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'
end
with_them do
it 'scrubs Redis commands' do
subject.detail_store << { cmd: cmd, duration: 1.second }
expect(subject.results[:details].count).to eq(1)
expect(subject.results[:details].first)
.to include({
cmd: expected,
duration: 1000
})
end
end
it 'returns aggregated results' do
subject.detail_store << { cmd: [:get, 'test'], duration: 0.001 }
subject.detail_store << { cmd: [:get, 'test'], duration: 1.second }
expect(subject.results[:calls]).to eq(2)
expect(subject.results[:duration]).to eq('1001.00ms')
expect(subject.results[:details].count).to eq(2)
end
end