Skip to content

Commit

Permalink
Refactor config options set in specs (#1204)
Browse files Browse the repository at this point in the history
Set the config options in the `start_agent` helper so we don't modify
the config hash directly midway through specs.
  • Loading branch information
tombruijn committed Jul 23, 2024
1 parent f65bee8 commit 5081c3a
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 123 deletions.
1 change: 0 additions & 1 deletion spec/lib/appsignal/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ def on_load
:active => true,
:push_api_key => "abc",
:name => "TestApp",
:request_headers => kind_of(Array),
:enable_minutely_probes => false
)
end
Expand Down
17 changes: 7 additions & 10 deletions spec/lib/appsignal/hooks/activejob_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@
["perform_start.active_job", "perform.active_job"]
end
end
let(:options) { {} }
before do
ActiveJob::Base.queue_adapter = :inline

start_agent
start_agent(:options => options)
Appsignal.internal_logger = test_logger(log)
class ActiveJobTestJob < ActiveJob::Base
def perform(*_args)
Expand Down Expand Up @@ -209,10 +210,9 @@ def perform(*_args)
end

context "with activejob_report_errors set to none" do
it "does not report the error" do
start_agent("production")
Appsignal.config[:activejob_report_errors] = "none"
let(:options) { { :activejob_report_errors => "none" } }

it "does not report the error" do
allow(Appsignal).to receive(:increment_counter)
tags = { :queue => queue }
expect(Appsignal).to receive(:increment_counter)
Expand All @@ -228,10 +228,7 @@ def perform(*_args)

if DependencyHelper.rails_version >= Gem::Version.new("7.1.0")
context "with activejob_report_errors set to discard" do
before do
start_agent("production")
Appsignal.config[:activejob_report_errors] = "discard"
end
let(:options) { { :activejob_report_errors => "discard" } }

it "does not report error on first failure" do
with_test_adapter do
Expand Down Expand Up @@ -351,9 +348,9 @@ def perform(*_args)
end

context "with params" do
let(:options) { { :filter_parameters => ["foo"] } }

it "filters the configured params" do
start_agent("production")
Appsignal.config[:filter_parameters] = ["foo"]
queue_job(ActiveJobTestJob, method_given_args)

transaction = last_transaction
Expand Down
15 changes: 10 additions & 5 deletions spec/lib/appsignal/hooks/gvl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
end
end
else
let(:options) { {} }
before do
start_agent
start_agent(:options => options)
end

def expect_gvltools_require
Expand Down Expand Up @@ -100,35 +101,39 @@ def self.enable

describe "#install" do
context "with enable_gvl_global_timer" do
let(:options) { { :enable_gvl_global_timer => true } }

it "enables the GVL global timer" do
Appsignal.config[:enable_gvl_global_timer] = true
expect(::GVLTools::GlobalTimer).to receive(:enable)

described_class.new.install
end
end

context "without enable_gvl_global_timer" do
let(:options) { { :enable_gvl_global_timer => false } }

it "does not enable the GVL global timer" do
Appsignal.config[:enable_gvl_global_timer] = false
expect(::GVLTools::GlobalTimer).not_to receive(:enable)

described_class.new.install
end
end

context "with enable_gvl_waiting_threads" do
let(:options) { { :enable_gvl_waiting_threads => true } }

it "enables the GVL waiting threads" do
Appsignal.config[:enable_gvl_global_timer] = true
expect(::GVLTools::WaitingThreads).to receive(:enable)

described_class.new.install
end
end

context "without enable_gvl_waiting_threads" do
let(:options) { { :enable_gvl_waiting_threads => false } }

it "does not enable the GVL waiting threads" do
Appsignal.config[:enable_gvl_waiting_threads] = false
expect(::GVLTools::WaitingThreads).not_to receive(:enable)

described_class.new.install
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/appsignal/hooks/http_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

describe Appsignal::Hooks::HttpHook do
before { start_agent }
let(:options) { {} }
before { start_agent(:options => options) }

if DependencyHelper.http_present?
context "with instrument_http_rb set to true" do
Expand All @@ -18,8 +19,7 @@
end

context "with instrument_http_rb set to false" do
before { Appsignal.config.config_hash[:instrument_http_rb] = false }
after { Appsignal.config.config_hash[:instrument_http_rb] = true }
let(:options) { { :instrument_http_rb => false } }

describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/appsignal/hooks/net_http_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe Appsignal::Hooks::NetHttpHook do
before { start_agent }
let(:options) { {} }
before { start_agent(:options => options) }

describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }
Expand All @@ -9,8 +10,7 @@
end

context "with Net::HTTP instrumentation disabled" do
before { Appsignal.config.config_hash[:instrument_net_http] = false }
after { Appsignal.config.config_hash[:instrument_net_http] = true }
let(:options) { { :instrument_net_http => false } }

it { is_expected.to be_falsy }
end
Expand Down
11 changes: 4 additions & 7 deletions spec/lib/appsignal/hooks/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
let(:helper) { Appsignal::Integrations::RakeIntegrationHelper }
let(:task) { Rake::Task.new("task:name", Rake::Application.new) }
let(:arguments) { Rake::TaskArguments.new(["foo"], ["bar"]) }
let(:options) { {} }
before do
start_agent
start_agent(:options => options)
allow(Kernel).to receive(:at_exit)
end
around { |example| keep_transactions { example.run } }
Expand All @@ -30,9 +31,7 @@ def perform
end

context "with :enable_rake_performance_instrumentation == false" do
before do
Appsignal.config[:enable_rake_performance_instrumentation] = false
end
let(:options) { { :enable_rake_performance_instrumentation => false } }

it "creates no transaction" do
expect { perform }.to_not(change { created_transactions.count })
Expand All @@ -49,9 +48,7 @@ def perform
end

context "with :enable_rake_performance_instrumentation == true" do
before do
Appsignal.config[:enable_rake_performance_instrumentation] = true
end
let(:options) { { :enable_rake_performance_instrumentation => true } }

it "creates a transaction" do
expect { perform }.to(change { created_transactions.count }.by(1))
Expand Down
15 changes: 5 additions & 10 deletions spec/lib/appsignal/hooks/redis_client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe Appsignal::Hooks::RedisClientHook do
let(:options) { {} }
before do
start_agent
start_agent(:options => options)
end

if DependencyHelper.redis_client_present?
Expand Down Expand Up @@ -30,9 +31,7 @@

context "with rest-client gem" do
describe "integration" do
before do
Appsignal.config.config_hash[:instrument_redis] = true
end
let(:options) { { :instrument_redis => true } }

context "install" do
before do
Expand Down Expand Up @@ -115,9 +114,7 @@ def write(_commands)
if DependencyHelper.hiredis_client_present?
context "with hiredis driver" do
describe "integration" do
before do
Appsignal.config.config_hash[:instrument_redis] = true
end
let(:options) { { :instrument_redis => true } }

context "install" do
before do
Expand Down Expand Up @@ -200,9 +197,7 @@ def write(_commands)
end

context "with instrumentation disabled" do
before do
Appsignal.config.config_hash[:instrument_redis] = false
end
let(:options) { { :instrument_redis => false } }

describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }
Expand Down
11 changes: 4 additions & 7 deletions spec/lib/appsignal/hooks/redis_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe Appsignal::Hooks::RedisHook do
before { start_agent }
let(:options) { {} }
before { start_agent(:options => options) }

if DependencyHelper.redis_present?
context "with redis" do
Expand All @@ -22,9 +23,7 @@
end

describe "integration" do
before do
Appsignal.config.config_hash[:instrument_redis] = true
end
let(:options) { { :instrument_redis => true } }

context "install" do
before do
Expand Down Expand Up @@ -103,9 +102,7 @@ def write(_commands)
end

context "with instrumentation disabled" do
before do
Appsignal.config.config_hash[:instrument_redis] = false
end
let(:options) { { :instrument_redis => false } }

describe "#dependencies_present?" do
subject { described_class.new.dependencies_present? }
Expand Down
8 changes: 3 additions & 5 deletions spec/lib/appsignal/hooks/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def perform_rescue_job(klass, options = {})

let(:queue) { "default" }
let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
let(:options) { {} }
before do
start_agent
start_agent(:options => options)

class ResqueTestJob
def self.perform(*_args)
Expand Down Expand Up @@ -82,10 +83,7 @@ def self.perform
end

context "with arguments" do
before do
start_agent("production")
Appsignal.config[:filter_parameters] = ["foo"]
end
let(:options) { { :filter_parameters => ["foo"] } }

it "filters out configured arguments" do
perform_rescue_job(
Expand Down
13 changes: 4 additions & 9 deletions spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def self.plugins
require "appsignal/integrations/delayed_job_plugin"
end
after(:context) { Object.send(:remove_const, :Delayed) }
before { start_agent }
let(:options) { {} }
before { start_agent(:options => options) }

# We haven't found a way to test the hooks, we'll have to do that manually

Expand Down Expand Up @@ -82,10 +83,7 @@ def perform
end

context "with parameter filtering" do
before do
start_agent("production")
Appsignal.config[:filter_parameters] = ["foo"]
end
let(:options) { { :filter_parameters => ["foo"] } }

it "filters selected arguments" do
perform
Expand Down Expand Up @@ -271,10 +269,7 @@ def self.appsignal_name
end

context "with parameter filtering" do
before do
start_agent("production")
Appsignal.config[:filter_parameters] = ["foo"]
end
let(:options) { { :filter_parameters => ["foo"] } }

it "filters selected arguments" do
perform
Expand Down
8 changes: 3 additions & 5 deletions spec/lib/appsignal/integrations/shoryuken_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DemoShoryukenWorker
let(:queue) { "some-funky-queue-name" }
let(:sqs_msg) { double(:message_id => "msg1", :attributes => {}) }
let(:body) { {} }
before { start_agent }
let(:options) { {} }
before { start_agent(:options => options) }
around { |example| keep_transactions { example.run } }

def perform_shoryuken_job(&block)
Expand Down Expand Up @@ -60,10 +61,7 @@ def perform_shoryuken_job(&block)
end

context "with parameter filtering" do
before do
start_agent("production")
Appsignal.config[:filter_parameters] = ["foo"]
end
let(:options) { { :filter_parameters => ["foo"] } }

it "filters selected arguments" do
perform_shoryuken_job
Expand Down
Loading

0 comments on commit 5081c3a

Please sign in to comment.