File tree Expand file tree Collapse file tree 3 files changed +40
-3
lines changed
instrumentation/net_http/test/opentelemetry/instrumentation/net/http Expand file tree Collapse file tree 3 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 198198 end
199199
200200 it 'does not create a span on connect when request ignored using a regexp' do
201+ # this works because http://bazqux.com is reachable site; try http://asdfasdfsef.com will fail
201202 uri = URI . parse ( 'http://bazqux.com' )
202203 http = Net ::HTTP . new ( uri . host , uri . port )
203- http . send ( :connect )
204+
205+ fake_socket = Object . new
206+ def fake_socket . setsockopt ( *args ) ; end
207+ def fake_socket . close ; end
208+
209+ # Replace the TCP socket creation with our fake socket
210+ TCPSocket . stub ( :open , fake_socket ) do
211+ http . send ( :connect )
212+ end
213+
204214 http . send ( :do_finish )
205215 _ ( exporter . finished_spans . size ) . must_equal 0
206216 end
252262 OpenTelemetry ::Common ::Utilities . untraced do
253263 uri = URI . parse ( 'http://example.com/body' )
254264 http = Net ::HTTP . new ( uri . host , uri . port )
265+
266+ # Mock the connect
267+ http . define_singleton_method ( :connect ) { true }
268+
255269 http . send ( :connect )
256270 http . send ( :do_finish )
257271 end
Original file line number Diff line number Diff line change 156156 # this works because http://bazqux.com is reachable site; try http://asdfasdfsef.com will fail
157157 uri = URI . parse ( 'http://bazqux.com' )
158158 http = Net ::HTTP . new ( uri . host , uri . port )
159- http . send ( :connect )
159+
160+ fake_socket = Object . new
161+ def fake_socket . setsockopt ( *args ) ; end
162+ def fake_socket . close ; end
163+
164+ # Replace the TCP socket creation with our fake socket
165+ TCPSocket . stub ( :open , fake_socket ) do
166+ http . send ( :connect )
167+ end
168+
160169 http . send ( :do_finish )
161170 _ ( exporter . finished_spans . size ) . must_equal 0
162171 end
Original file line number Diff line number Diff line change 169169 end
170170
171171 it 'does not create a span on connect when request ignored using a regexp' do
172+ # this works because http://bazqux.com is reachable site; try http://asdfasdfsef.com will fail
172173 uri = URI . parse ( 'http://bazqux.com' )
173174 http = Net ::HTTP . new ( uri . host , uri . port )
174- http . send ( :connect )
175+
176+ fake_socket = Object . new
177+ def fake_socket . setsockopt ( *args ) ; end
178+ def fake_socket . close ; end
179+
180+ # Replace the TCP socket creation with our fake socket
181+ TCPSocket . stub ( :open , fake_socket ) do
182+ http . send ( :connect )
183+ end
184+
175185 http . send ( :do_finish )
176186 _ ( exporter . finished_spans . size ) . must_equal 0
177187 end
217227 OpenTelemetry ::Common ::Utilities . untraced do
218228 uri = URI . parse ( 'http://example.com/body' )
219229 http = Net ::HTTP . new ( uri . host , uri . port )
230+
231+ # Mock the connect
232+ http . define_singleton_method ( :connect ) { true }
233+
220234 http . send ( :connect )
221235 http . send ( :do_finish )
222236 end
You can’t perform that action at this time.
0 commit comments