From e00665afb8cfdb99d126402a8fb67817780c2e3b Mon Sep 17 00:00:00 2001 From: David Elner Date: Fri, 8 Mar 2019 12:51:41 -0500 Subject: [PATCH] Fixed: Analytics shared examples breaking when global state lingers. --- spec/ddtrace/contrib/delayed_job/plugin_spec.rb | 7 ++++++- spec/ddtrace/contrib/racecar/patcher_spec.rb | 7 ++++++- spec/ddtrace/contrib/rack/configuration_spec.rb | 7 ++++++- spec/ddtrace/contrib/rake/instrumentation_spec.rb | 6 ++++-- spec/ddtrace/contrib/resque/instrumentation_spec.rb | 7 ++++++- spec/ddtrace/contrib/shoryuken/tracer_spec.rb | 7 ++++++- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/spec/ddtrace/contrib/delayed_job/plugin_spec.rb b/spec/ddtrace/contrib/delayed_job/plugin_spec.rb index 8698dc38f4b..0dea6785a8f 100644 --- a/spec/ddtrace/contrib/delayed_job/plugin_spec.rb +++ b/spec/ddtrace/contrib/delayed_job/plugin_spec.rb @@ -34,7 +34,12 @@ def job_data Delayed::Worker.delay_jobs = false end - after(:each) { Datadog.registry[:delayed_job].reset_configuration! } + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:delayed_job].reset_configuration! + example.run + Datadog.registry[:delayed_job].reset_configuration! + end describe 'instrumenting worker execution' do let(:worker) { double(:worker, name: 'worker') } diff --git a/spec/ddtrace/contrib/racecar/patcher_spec.rb b/spec/ddtrace/contrib/racecar/patcher_spec.rb index c2787888846..e2e5d60e05d 100644 --- a/spec/ddtrace/contrib/racecar/patcher_spec.rb +++ b/spec/ddtrace/contrib/racecar/patcher_spec.rb @@ -19,7 +19,12 @@ def all_spans end end - after(:each) { Datadog.registry[:racecar].reset_configuration! } + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:racecar].reset_configuration! + example.run + Datadog.registry[:racecar].reset_configuration! + end describe 'for single message processing' do let(:topic) { 'dd_trace_test_dummy' } diff --git a/spec/ddtrace/contrib/rack/configuration_spec.rb b/spec/ddtrace/contrib/rack/configuration_spec.rb index b98ef787cd6..929abab2cdb 100644 --- a/spec/ddtrace/contrib/rack/configuration_spec.rb +++ b/spec/ddtrace/contrib/rack/configuration_spec.rb @@ -21,7 +21,12 @@ end end - after(:each) { Datadog.registry[:rack].reset_configuration! } + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:rack].reset_configuration! + example.run + Datadog.registry[:rack].reset_configuration! + end shared_context 'an incoming HTTP request' do subject(:response) { get '/' } diff --git a/spec/ddtrace/contrib/rake/instrumentation_spec.rb b/spec/ddtrace/contrib/rake/instrumentation_spec.rb index 7b978e5c132..c208e6cbf71 100644 --- a/spec/ddtrace/contrib/rake/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/rake/instrumentation_spec.rb @@ -25,8 +25,10 @@ end end - after(:each) do - # Reset configuration to defaults + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:rake].reset_configuration! + example.run Datadog.registry[:rake].reset_configuration! # We don't want instrumentation enabled during the rest of the test suite... diff --git a/spec/ddtrace/contrib/resque/instrumentation_spec.rb b/spec/ddtrace/contrib/resque/instrumentation_spec.rb index 0b73a7cd1d0..43eb5bcf078 100644 --- a/spec/ddtrace/contrib/resque/instrumentation_spec.rb +++ b/spec/ddtrace/contrib/resque/instrumentation_spec.rb @@ -28,7 +28,12 @@ end end - after(:each) { Datadog.registry[:resque].reset_configuration! } + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:resque].reset_configuration! + example.run + Datadog.registry[:resque].reset_configuration! + end shared_examples 'job execution tracing' do context 'that succeeds' do diff --git a/spec/ddtrace/contrib/shoryuken/tracer_spec.rb b/spec/ddtrace/contrib/shoryuken/tracer_spec.rb index ff3d7d37c13..acb57abfe57 100644 --- a/spec/ddtrace/contrib/shoryuken/tracer_spec.rb +++ b/spec/ddtrace/contrib/shoryuken/tracer_spec.rb @@ -20,7 +20,12 @@ end end - after { Datadog.registry[:shoryuken].reset_configuration! } + around do |example| + # Reset before and after each example; don't allow global state to linger. + Datadog.registry[:shoryuken].reset_configuration! + example.run + Datadog.registry[:shoryuken].reset_configuration! + end shared_context 'Shoryuken::Worker' do let(:worker_class) do