From a877d83514c5adfd9d036b7ee62791ceb4ae9b3a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev <156273877+p-datadog@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:55:53 -0400 Subject: [PATCH] DEBUG-2334 Add integration_test helper (#3961) * DEBUG-2334 Add integration_test helper DRY the logic to skip integration tests into a class-level helper * rubocop * rename helper to skip_unless_integration_testing_enabled --------- Co-authored-by: Oleg Pudeyev --- .../core/remote/transport/integration_spec.rb | 2 +- .../tracing/contrib/ethon/integration_test_spec.rb | 2 +- .../contrib/ethon/typhoeus_integration_spec.rb | 2 +- .../tracing/contrib/redis/instrumentation_spec.rb | 6 ++---- .../tracing/contrib/redis/integration_test_spec.rb | 4 ++-- spec/datadog/tracing/contrib/redis/miniapp_spec.rb | 2 +- spec/datadog/tracing/integration_spec.rb | 4 ++-- .../http/adapters/net_integration_spec.rb | 2 +- .../http/adapters/unix_socket_integration_spec.rb | 2 +- .../tracing/transport/http/integration_spec.rb | 2 +- spec/support/core_helpers.rb | 14 ++++++++++++++ spec/support/test_helpers.rb | 6 +----- 12 files changed, 28 insertions(+), 20 deletions(-) diff --git a/spec/datadog/core/remote/transport/integration_spec.rb b/spec/datadog/core/remote/transport/integration_spec.rb index a68589d6b9a..6f24ca1f6b5 100644 --- a/spec/datadog/core/remote/transport/integration_spec.rb +++ b/spec/datadog/core/remote/transport/integration_spec.rb @@ -8,7 +8,7 @@ require 'datadog/core/remote/transport/negotiation' RSpec.describe Datadog::Core::Remote::Transport::HTTP do - before { skip unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled describe '.root' do subject(:transport) { described_class.root(&client_options) } diff --git a/spec/datadog/tracing/contrib/ethon/integration_test_spec.rb b/spec/datadog/tracing/contrib/ethon/integration_test_spec.rb index d1f10398b09..da0d67b894e 100644 --- a/spec/datadog/tracing/contrib/ethon/integration_test_spec.rb +++ b/spec/datadog/tracing/contrib/ethon/integration_test_spec.rb @@ -13,7 +13,7 @@ require 'spec/datadog/tracing/contrib/ethon/support/thread_helpers' RSpec.describe 'Ethon integration tests' do - before { skip unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled context 'with Easy HTTP request' do subject(:request) do diff --git a/spec/datadog/tracing/contrib/ethon/typhoeus_integration_spec.rb b/spec/datadog/tracing/contrib/ethon/typhoeus_integration_spec.rb index b4041fc0629..cf9c5ef5a63 100644 --- a/spec/datadog/tracing/contrib/ethon/typhoeus_integration_spec.rb +++ b/spec/datadog/tracing/contrib/ethon/typhoeus_integration_spec.rb @@ -5,7 +5,7 @@ require 'spec/datadog/tracing/contrib/ethon/support/thread_helpers' RSpec.describe Datadog::Tracing::Contrib::Ethon do - before { skip unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled before(:context) do # Ethon will lazily initialize LibCurl, diff --git a/spec/datadog/tracing/contrib/redis/instrumentation_spec.rb b/spec/datadog/tracing/contrib/redis/instrumentation_spec.rb index 847b50c1527..9ac8c4d8b34 100644 --- a/spec/datadog/tracing/contrib/redis/instrumentation_spec.rb +++ b/spec/datadog/tracing/contrib/redis/instrumentation_spec.rb @@ -4,6 +4,8 @@ require 'datadog' RSpec.describe 'Redis instrumentation test' do + skip_unless_integration_testing_enabled + let(:test_host) { ENV.fetch('TEST_REDIS_HOST', '127.0.0.1') } let(:test_port) { ENV.fetch('TEST_REDIS_PORT', 6379).to_i } @@ -20,10 +22,6 @@ Datadog.registry[:redis].reset_configuration! end - before do - skip unless ENV['TEST_DATADOG_INTEGRATION'] - end - RSpec::Matchers.define :be_a_redis_span do match(notify_expectation_failures: true) do |span| expect(span.name).to eq('redis.command') diff --git a/spec/datadog/tracing/contrib/redis/integration_test_spec.rb b/spec/datadog/tracing/contrib/redis/integration_test_spec.rb index 2542ce7bdcd..57c23eda541 100644 --- a/spec/datadog/tracing/contrib/redis/integration_test_spec.rb +++ b/spec/datadog/tracing/contrib/redis/integration_test_spec.rb @@ -5,9 +5,9 @@ require 'datadog' RSpec.describe 'Redis integration test' do - before do - skip unless ENV['TEST_DATADOG_INTEGRATION'] + skip_unless_integration_testing_enabled + before do use_real_tracer! Datadog.configure do |c| diff --git a/spec/datadog/tracing/contrib/redis/miniapp_spec.rb b/spec/datadog/tracing/contrib/redis/miniapp_spec.rb index 528b3251060..5864d453719 100644 --- a/spec/datadog/tracing/contrib/redis/miniapp_spec.rb +++ b/spec/datadog/tracing/contrib/redis/miniapp_spec.rb @@ -6,7 +6,7 @@ require 'datadog' RSpec.describe 'Redis mini app test' do - before { skip unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled before do Datadog.configure { |c| c.tracing.instrument :redis } diff --git a/spec/datadog/tracing/integration_spec.rb b/spec/datadog/tracing/integration_spec.rb index 4aa9cd4fe66..c0d5b95021a 100644 --- a/spec/datadog/tracing/integration_spec.rb +++ b/spec/datadog/tracing/integration_spec.rb @@ -20,9 +20,9 @@ RSpec.describe 'Tracer integration tests' do shared_context 'agent-based test' do - before do - skip unless ENV['TEST_DATADOG_INTEGRATION'] + skip_unless_integration_testing_enabled + before do # Ensure background Writer worker doesn't wait, making tests faster. stub_const('Datadog::Tracing::Workers::AsyncTransport::DEFAULT_FLUSH_INTERVAL', 0) diff --git a/spec/datadog/tracing/transport/http/adapters/net_integration_spec.rb b/spec/datadog/tracing/transport/http/adapters/net_integration_spec.rb index 9edf8756dc0..e10bbe4d1f5 100644 --- a/spec/datadog/tracing/transport/http/adapters/net_integration_spec.rb +++ b/spec/datadog/tracing/transport/http/adapters/net_integration_spec.rb @@ -7,7 +7,7 @@ require 'datadog/core/transport/http/adapters/net' RSpec.describe 'Adapters::Net tracing integration tests' do - before { skip('Skipping test as ENV["TEST_DATADOG_INTEGRATION"] is not set') unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled subject(:adapter) { Datadog::Core::Transport::HTTP::Adapters::Net.new(agent_settings) } diff --git a/spec/datadog/tracing/transport/http/adapters/unix_socket_integration_spec.rb b/spec/datadog/tracing/transport/http/adapters/unix_socket_integration_spec.rb index 4e3230cc31a..41b1efb5494 100644 --- a/spec/datadog/tracing/transport/http/adapters/unix_socket_integration_spec.rb +++ b/spec/datadog/tracing/transport/http/adapters/unix_socket_integration_spec.rb @@ -7,7 +7,7 @@ require 'datadog/core/transport/http/adapters/unix_socket' RSpec.describe 'Adapters::UnixSocket integration tests' do - before { skip unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled subject(:adapter) { Datadog::Core::Transport::HTTP::Adapters::UnixSocket.new(**options) } diff --git a/spec/datadog/tracing/transport/http/integration_spec.rb b/spec/datadog/tracing/transport/http/integration_spec.rb index 9dc6a558eba..e93926a7c80 100644 --- a/spec/datadog/tracing/transport/http/integration_spec.rb +++ b/spec/datadog/tracing/transport/http/integration_spec.rb @@ -6,7 +6,7 @@ require 'datadog/tracing/transport/traces' RSpec.describe 'Datadog::Tracing::Transport::HTTP integration tests' do - before { skip unless ENV['TEST_DATADOG_INTEGRATION'] } + skip_unless_integration_testing_enabled describe 'HTTP#default' do subject(:transport) { Datadog::Tracing::Transport::HTTP.default(&client_options) } diff --git a/spec/support/core_helpers.rb b/spec/support/core_helpers.rb index 9764d74d28d..27e3f94320f 100644 --- a/spec/support/core_helpers.rb +++ b/spec/support/core_helpers.rb @@ -44,4 +44,18 @@ def supports_value_expectations? false end end + + module ClassMethods + def skip_unless_integration_testing_enabled + unless ENV['TEST_DATADOG_INTEGRATION'] + before(:all) do + skip 'Set TEST_DATADOG_INTEGRATION=1 in environment to run this test' + end + end + end + end + + def self.included(base) + base.extend ClassMethods + end end diff --git a/spec/support/test_helpers.rb b/spec/support/test_helpers.rb index 40d10b98c54..06f49b94d5f 100644 --- a/spec/support/test_helpers.rb +++ b/spec/support/test_helpers.rb @@ -11,11 +11,7 @@ module RSpec module Integration def self.included(base) base.class_exec do - before do - unless ENV['TEST_DATADOG_INTEGRATION'] - skip('Integration tests can be enabled by setting the environment variable `TEST_DATADOG_INTEGRATION=1`') - end - end + skip_unless_integration_testing_enabled include_context 'non-development execution environment' end