Skip to content

Commit

Permalink
Testing updates (#1399)
Browse files Browse the repository at this point in the history
* use local objects for context blocks

* Move sleep to before block

* Localize subject var

* Set local vars in test instead of let
  • Loading branch information
estolfo committed Aug 15, 2023
1 parent 894c09a commit 6fccf49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 13 additions & 4 deletions spec/elastic_apm/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ module ElasticAPM
RSpec.describe Metrics do
let(:config) { Config.new }
let(:callback) { ->(_) {} }
subject { described_class.new(config, &callback) }

describe 'life cycle' do
subject { described_class.new(config, &callback) }

describe '#start' do
before { subject.start }
it { should be_running }
Expand Down Expand Up @@ -65,10 +66,12 @@ module ElasticAPM
end

describe '.new' do
subject { described_class.new(config, &callback) }
it { should be_a Metrics::Registry }
end

describe '.collect' do
subject { described_class.new(config, &callback) }
after { subject.stop }

it 'samples all samplers' do
Expand All @@ -82,6 +85,8 @@ module ElasticAPM

describe '.collect_and_send' do
context 'when samples' do
subject { described_class.new(config, &callback) }
let(:callback) { ->(_) {} }
before { subject.start }
after { subject.stop }

Expand All @@ -95,20 +100,23 @@ module ElasticAPM
end

context 'when no samples' do
before { subject.start }
after { subject.stop }

it 'calls callback' do
callback = ->(_) {}
subject = described_class.new(config, &callback)
subject.start
subject.sets.each_value do |sampler|
expect(sampler).to receive(:collect).at_least(:once) { nil }
end
expect(callback).to_not receive(:call)

subject.collect_and_send
subject.stop
end
end

context 'when recording is false' do
subject { described_class.new(config, &callback) }
let(:callback) { ->(_) {} }
let(:config) { Config.new(recording: false) }
it 'does not collect metrics' do
expect(subject).to_not receive(:collect)
Expand Down Expand Up @@ -170,6 +178,7 @@ module ElasticAPM
end

describe '#handle_forking!' do
subject { described_class.new(config, &callback) }
before do
subject.handle_forking!
end
Expand Down
3 changes: 2 additions & 1 deletion spec/elastic_apm/spies/sucker_punch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ def perform
before do
with_agent do
TestJob.perform_async
sleep(0.5)
sleep(1)
end
end

it 'creates a transaction' do

expect(@intercepted.transactions.size).to eq 1
transaction, = @intercepted.transactions
expect(transaction.name).to eq 'ElasticAPM::TestJob'
Expand Down

0 comments on commit 6fccf49

Please sign in to comment.