File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
instrumentation/net_http/test/opentelemetry/instrumentation/net/http Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 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 )
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' )
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
You can’t perform that action at this time.
0 commit comments