@@ -199,6 +199,7 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix
199199 appActivity : 'io.appium.android.apis.ApiDemos' ,
200200 someCapability : 'some_capability' ,
201201 'appium:directConnectProtocol' => 'https' ,
202+ # Not the best, but to include tests with host name
202203 'appium:directConnectHost' => 'appium.io' ,
203204 'appium:directConnectPort' => '8888' ,
204205 'appium:directConnectPath' => '/wd/hub'
@@ -331,6 +332,48 @@ def test_direct_connect_loopback_host_falls_back_to_original_url
331332 assert_not_requested ( :post , 'http://localhost:8888/wd/hub/session/1234567890/timeouts' )
332333 end
333334
335+ def test_direct_connect_dns_timeout_falls_back_to_original_url
336+ response = {
337+ value : {
338+ sessionId : '1234567890' ,
339+ capabilities : {
340+ platformName : :android ,
341+ automationName : ENV [ 'APPIUM_DRIVER' ] || 'uiautomator2' ,
342+ app : 'test/functional/app/ApiDemos-debug.apk' ,
343+ platformVersion : '7.1.1' ,
344+ deviceName : 'Android Emulator' ,
345+ appPackage : 'io.appium.android.apis' ,
346+ appActivity : 'io.appium.android.apis.ApiDemos' ,
347+ someCapability : 'some_capability' ,
348+ directConnectProtocol : 'http' ,
349+ directConnectHost : 'slow.example.internal' ,
350+ directConnectPort : '8888' ,
351+ directConnectPath : '/wd/hub'
352+ }
353+ }
354+ } . to_json
355+
356+ stub_request ( :post , 'http://127.0.0.1:4723/session' )
357+ . to_return ( headers : HEADER , status : 200 , body : response )
358+
359+ stub_request ( :post , 'http://127.0.0.1:4723/session/1234567890/timeouts' )
360+ . with ( body : { implicit : 30_000 } . to_json )
361+ . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
362+
363+ Socket . stub ( :getaddrinfo , -> ( *) { raise Timeout ::Error } ) do
364+ core = ::Appium ::Core . for ( Caps . android_direct )
365+ driver = core . start_driver
366+
367+ uri = driver . send ( :bridge ) . http . send ( :server_url )
368+ assert_equal 'http' , uri . scheme
369+ assert_equal '127.0.0.1' , uri . host
370+ assert_equal 4723 , uri . port
371+
372+ assert_requested ( :post , 'http://127.0.0.1:4723/session' , times : 1 )
373+ assert_not_requested ( :post , 'http://slow.example.internal:8888/wd/hub/session/1234567890/timeouts' )
374+ end
375+ end
376+
334377 def test_default_timeout_for_http_client_with_direct_no_path
335378 android_mock_create_session_w3c_direct_no_path = lambda do |core |
336379 response = {
0 commit comments