diff --git a/instrumentation/aws_sdk/test/opentelemetry/patches/telemetry_test.rb b/instrumentation/aws_sdk/test/opentelemetry/patches/telemetry_test.rb index 55fd838864..1bff99c618 100644 --- a/instrumentation/aws_sdk/test/opentelemetry/patches/telemetry_test.rb +++ b/instrumentation/aws_sdk/test/opentelemetry/patches/telemetry_test.rb @@ -39,7 +39,7 @@ describe 'Lambda' do let(:service_name) { 'Lambda' } let(:service_uri) do - 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/' + 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions' end let(:client) do Aws::Lambda::Client.new( @@ -82,7 +82,7 @@ it 'creates spans with all the non-stubbed parameters' do skip unless TestHelper.telemetry_plugin?(service_name) - stub_request(:get, 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/') + stub_request(:get, 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions') client = Aws::Lambda::Client.new( telemetry_provider: otel_provider, diff --git a/instrumentation/net_http/test/opentelemetry/instrumentation/net/http/instrumentation_test.rb b/instrumentation/net_http/test/opentelemetry/instrumentation/net/http/instrumentation_test.rb index fb4d61a92a..e3961349d5 100644 --- a/instrumentation/net_http/test/opentelemetry/instrumentation/net/http/instrumentation_test.rb +++ b/instrumentation/net_http/test/opentelemetry/instrumentation/net/http/instrumentation_test.rb @@ -151,6 +151,7 @@ end it 'does not create a span on connect when request ignored using a regexp' do + # this works because http://bazqux.com is reachable site; try http://asdfasdfsef.com will fail uri = URI.parse('http://bazqux.com') http = Net::HTTP.new(uri.host, uri.port) http.send(:connect) @@ -169,7 +170,16 @@ it 'creates a span on connect for a non-ignored request' do uri = URI.parse('http://example.com') http = Net::HTTP.new(uri.host, uri.port) - http.send(:connect) + + fake_socket = Object.new + def fake_socket.setsockopt(*args); end + def fake_socket.close; end + + # Replace the TCP socket creation with our fake socket + TCPSocket.stub(:open, fake_socket) do + http.send(:connect) + end + http.send(:do_finish) _(exporter.finished_spans.size).must_equal 1 _(span.name).must_equal('connect') @@ -199,6 +209,10 @@ OpenTelemetry::Common::Utilities.untraced do uri = URI.parse('http://example.com/body') http = Net::HTTP.new(uri.host, uri.port) + + # Mock the connect + http.define_singleton_method(:connect) { true } + http.send(:connect) http.send(:do_finish) end