diff options
Diffstat (limited to 'spec/lib/peek')
-rw-r--r-- | spec/lib/peek/views/bullet_detailed_spec.rb | 54 | ||||
-rw-r--r-- | spec/lib/peek/views/redis_detailed_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/peek/views/rugged_spec.rb | 2 |
3 files changed, 62 insertions, 7 deletions
diff --git a/spec/lib/peek/views/bullet_detailed_spec.rb b/spec/lib/peek/views/bullet_detailed_spec.rb new file mode 100644 index 00000000000..a482cadc7db --- /dev/null +++ b/spec/lib/peek/views/bullet_detailed_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Peek::Views::BulletDetailed do + subject { described_class.new } + + before do + allow(Bullet).to receive(:enable?).and_return(bullet_enabled) + end + + context 'bullet disabled' do + let(:bullet_enabled) { false } + + it 'returns empty results' do + expect(subject.results).to eq({}) + end + end + + context 'bullet enabled' do + let(:bullet_enabled) { true } + + before do + allow(Bullet).to receive_message_chain(:notification_collector, :collection).and_return(notifications) + end + + context 'where there are no notifications' do + let(:notifications) { [] } + + it 'returns empty results' do + expect(subject.results).to eq({}) + end + end + + context 'when notifications exist' do + let(:notifications) do + [ + double(title: 'Title 1', body: 'Body 1', body_with_caller: "first\nsecond\n"), + double(title: 'Title 2', body: 'Body 2', body_with_caller: "first\nsecond\n") + ] + end + + it 'returns empty results' do + expect(subject.key).to eq('bullet') + expect(subject.results[:calls]).to eq(2) + expect(subject.results[:warnings]).to eq([Peek::Views::BulletDetailed::WARNING_MESSAGE]) + expect(subject.results[:details]).to eq([ + { notification: 'Title 1: Body 1', backtrace: "first\nsecond\n" }, + { notification: 'Title 2: Body 2', backtrace: "first\nsecond\n" } + ]) + end + end + end +end diff --git a/spec/lib/peek/views/redis_detailed_spec.rb b/spec/lib/peek/views/redis_detailed_spec.rb index fa9532226f2..a270c006a43 100644 --- a/spec/lib/peek/views/redis_detailed_spec.rb +++ b/spec/lib/peek/views/redis_detailed_spec.rb @@ -17,7 +17,7 @@ describe Peek::Views::RedisDetailed, :request_store do with_them do it 'scrubs Redis commands' do - subject.detail_store << { cmd: cmd, duration: 1.second } + Gitlab::Instrumentation::Redis::SharedState.detail_store << { cmd: cmd, duration: 1.second } expect(subject.results[:details].count).to eq(1) expect(subject.results[:details].first) @@ -29,11 +29,12 @@ describe Peek::Views::RedisDetailed, :request_store do end it 'returns aggregated results' do - subject.detail_store << { cmd: [:get, 'test'], duration: 0.001 } - subject.detail_store << { cmd: [:get, 'test'], duration: 1.second } + Gitlab::Instrumentation::Redis::Cache.detail_store << { cmd: [:get, 'test'], duration: 0.001 } + Gitlab::Instrumentation::Redis::Cache.detail_store << { cmd: [:get, 'test'], duration: 1.second } + Gitlab::Instrumentation::Redis::SharedState.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) + expect(subject.results[:calls]).to eq(3) + expect(subject.results[:duration]).to eq('2001.00ms') + expect(subject.results[:details].count).to eq(3) end end diff --git a/spec/lib/peek/views/rugged_spec.rb b/spec/lib/peek/views/rugged_spec.rb index b9507f772d2..39968afed39 100644 --- a/spec/lib/peek/views/rugged_spec.rb +++ b/spec/lib/peek/views/rugged_spec.rb @@ -16,7 +16,7 @@ describe Peek::Views::Rugged, :request_store do end it 'returns aggregated results' do - ::Gitlab::RuggedInstrumentation.query_time += 1.234 + ::Gitlab::RuggedInstrumentation.add_query_time(1.234) ::Gitlab::RuggedInstrumentation.increment_query_count ::Gitlab::RuggedInstrumentation.increment_query_count |