Skip to content

Commit 5a43d86

Browse files
authored
fix: net_http and aws_sdk ci fix (#1604)
* fix: mock the connect method when using it in net-http test case * remove tailing /
1 parent c3edc8d commit 5a43d86

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

instrumentation/aws_sdk/test/opentelemetry/patches/telemetry_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
describe 'Lambda' do
4040
let(:service_name) { 'Lambda' }
4141
let(:service_uri) do
42-
'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/'
42+
'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions'
4343
end
4444
let(:client) do
4545
Aws::Lambda::Client.new(
@@ -82,7 +82,7 @@
8282

8383
it 'creates spans with all the non-stubbed parameters' do
8484
skip unless TestHelper.telemetry_plugin?(service_name)
85-
stub_request(:get, 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/')
85+
stub_request(:get, 'https://lambda.us-east-1.amazonaws.com/2015-03-31/functions')
8686

8787
client = Aws::Lambda::Client.new(
8888
telemetry_provider: otel_provider,

instrumentation/net_http/test/opentelemetry/instrumentation/net/http/instrumentation_test.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
end
152152

153153
it 'does not create a span on connect when request ignored using a regexp' do
154+
# this works because http://bazqux.com is reachable site; try http://asdfasdfsef.com will fail
154155
uri = URI.parse('http://bazqux.com')
155156
http = Net::HTTP.new(uri.host, uri.port)
156157
http.send(:connect)
@@ -169,7 +170,16 @@
169170
it 'creates a span on connect for a non-ignored request' do
170171
uri = URI.parse('http://example.com')
171172
http = Net::HTTP.new(uri.host, uri.port)
172-
http.send(:connect)
173+
174+
fake_socket = Object.new
175+
def fake_socket.setsockopt(*args); end
176+
def fake_socket.close; end
177+
178+
# Replace the TCP socket creation with our fake socket
179+
TCPSocket.stub(:open, fake_socket) do
180+
http.send(:connect)
181+
end
182+
173183
http.send(:do_finish)
174184
_(exporter.finished_spans.size).must_equal 1
175185
_(span.name).must_equal('connect')
@@ -199,6 +209,10 @@
199209
OpenTelemetry::Common::Utilities.untraced do
200210
uri = URI.parse('http://example.com/body')
201211
http = Net::HTTP.new(uri.host, uri.port)
212+
213+
# Mock the connect
214+
http.define_singleton_method(:connect) { true }
215+
202216
http.send(:connect)
203217
http.send(:do_finish)
204218
end

0 commit comments

Comments
 (0)