Skip to content

Commit

Permalink
Merge pull request #1023 from DataDog/fix/components_teardown_nil_stats
Browse files Browse the repository at this point in the history
Fix Components#teardown! NoMethodError
  • Loading branch information
delner authored May 5, 2020
2 parents 8209ab5 + 817a908 commit c8e2fa4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ddtrace/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ def teardown!(replacement = nil)
old_statsd = [
runtime_metrics.metrics.statsd,
health_metrics.statsd
].uniq
].compact.uniq

new_statsd = if replacement
[
replacement.runtime_metrics.metrics.statsd,
replacement.health_metrics.statsd
].uniq
].compact.uniq
else
[]
end
Expand Down
19 changes: 19 additions & 0 deletions spec/ddtrace/configuration/components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,25 @@

teardown!
end

context 'and Statsd is not initialized' do
before do
allow(components.runtime_metrics.metrics)
.to receive(:statsd)
.and_return(nil)
end

it 'shuts down all components' do
expect(components.tracer).to receive(:shutdown!)
expect(components.runtime_metrics).to receive(:enabled=)
.with(false)
expect(components.runtime_metrics).to receive(:stop)
.with(true)
expect(components.health_metrics.statsd).to receive(:close)

teardown!
end
end
end

context 'when the tracer is re-used' do
Expand Down

0 comments on commit c8e2fa4

Please sign in to comment.