Skip to content

Commit

Permalink
Socket Timeout added. PyYAML upgraded to 6.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-verma committed Dec 1, 2021
1 parent af74e08 commit 8d74d80
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELIST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Future Themes (In-Progress or Planned):

1.2.13
------
- BUGFIX: HTTP layer tests at times got stuck after one test. This seems to happen when the socket library is not passed a timeout.
- A default socket timeout of 60 seconds is now configured.
- It can be changed at project level or in CLI options using SOCKET_TIMEOUT property.

1.2.12
------
Expand Down
1 change: 1 addition & 0 deletions arjuna/configure/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"HTTP_PROXY_ENABLED",
"HTTP_PROXY_HOST",
"HTTP_PROXY_PORT",
"SOCKET_TIMEOUT"
},

ConfigStage.REFERENCE: {
Expand Down
1 change: 0 additions & 1 deletion arjuna/engine/pytestplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from arjuna.tpi.error import *
from arjuna.tpi.parser.yaml import Yaml


_ARJUNA_CLI_ARGS = {
"project": ("--project", {
"dest":"project",
Expand Down
9 changes: 6 additions & 3 deletions arjuna/interact/http/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _send(self, request) -> HttpResponse:
Returns
`HttpResponse` object. In case of redirections, this is the last HttpResponse object, which encapsulates all redirections which can be retrieved from it.
'''
from arjuna import Arjuna, log_info
from arjuna import Arjuna, log_info, C
from arjuna.tpi.helper.arjtype import NetworkPacketInfo
log_info(request.label)
max_connection_retries = 5
Expand All @@ -203,10 +203,13 @@ def _send(self, request) -> HttpResponse:
while counter < max_connection_retries:
counter += 1
try:
timeout = C("socket.timeout")
if request.timeout is not None:
timeout = request.timeout
if self._session.proxies:
response = HttpResponse(self, self._session.send(request._request, allow_redirects=request.allow_redirects, timeout=request.timeout, proxies=self._session.proxies, verify=False))
response = HttpResponse(self, self._session.send(request._request, allow_redirects=request.allow_redirects, timeout=timeout, proxies=self._session.proxies, verify=False))
else:
response = HttpResponse(self, self._session.send(request._request, allow_redirects=request.allow_redirects, timeout=request.timeout))
response = HttpResponse(self, self._session.send(request._request, allow_redirects=request.allow_redirects, timeout=timeout))
except (ProxyError, InvalidProxyURL) as e:
raise HttpConnectError(request, "There is an error in connecting to the configured proxy. Proxy settings: {}. Error: {}".format(self.__session.proxies, str(e)))
except ConnectionError as f:
Expand Down
1 change: 1 addition & 0 deletions arjuna/res/arjuna.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

function openModal(event){
var source = event.target || event.srcElement;
var modal = document.getElementById("modal-packet");
Expand Down
1 change: 1 addition & 0 deletions arjuna/res/arjuna.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ arjuna_options:

app.url: NOT_SET

socket.timeout: 60
http.proxy.enabled: False
http.proxy.host: localhost
http.proxy.port: 8080
Expand Down
1 change: 1 addition & 0 deletions arjuna/res/arjuna_conf_desc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data.file.dir: absolute_dir_path

app.url: web_url

socket.timeout: int
http.proxy.enabled: bool
http.proxy.host: str
http.proxy.port: int
Expand Down
3 changes: 3 additions & 0 deletions arjuna/tpi/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class ArjunaOption(Enum):
APP_URL = auto()
'''Base URL for a Web App. Used by launch() method if url is not specified for GuiApp.'''

SOCKET_TIMEOUT = auto()
'''Timeout for socket connections. Default is 60 seconds.'''

HTTP_PROXY_ENABLED = auto()
'''Is a proxy enabled for HTTP requests (GUIAuto as well as HttpAuto)'''

Expand Down
2 changes: 2 additions & 0 deletions arjuna/tpi/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def copy_file(src, dest):
self.__logger = Logger(self.ref_config)
from arjuna import ArjunaOption
self.__allowed_log_contexts = self.ref_config.value(ArjunaOption.LOG_ALLOWED_CONTEXTS)
import socket
socket.setdefaulttimeout(self.ref_config.value(ArjunaOption.SOCKET_TIMEOUT))

from arjuna.tpi.hook.config import Configurator
configurator = Configurator()
Expand Down
8 changes: 4 additions & 4 deletions arjuna/tpi/engine/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def _call_func(func, request_wrapper, data=None, *args, **kwargs):
log_info("Begin test function: {}".format(qual_name))
try:
if data:
func(request=request_wrapper, data=data, *args, **kwargs)
return func(request=request_wrapper, data=data, *args, **kwargs)
else:
func(request=request_wrapper, *args, **kwargs)
return func(request=request_wrapper, *args, **kwargs)
except Exception as e:
log_info("End test function (with failure/error): {}. Exception Message: {}".format(qual_name, str(e)))
raise e
Expand Down Expand Up @@ -289,12 +289,12 @@ def format_test_func(func):
@functools.wraps(orig_func)
def wrapper_without_data(request, *args, **kwargs):
my.set_req_obj(request)
_call_func(func, my, *args, **kwargs)
return _call_func(func, my, *args, **kwargs)

@functools.wraps(orig_func)
def wrapper_with_data(request, data, *args, **kwargs):
my.set_req_obj(request)
_call_func(func, my, data, *args, **kwargs)
return _call_func(func, my, data, *args, **kwargs)

if drive_with:
return wrapper_with_data
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"pytest==6.2.1",
"pytest-html==2.1.1",
"pytest-dependency==0.4.0",
"PyYAML==5.3",
"PyYAML==6.0",
"mimesis==4.1.3",
"jsonpath-rw==1.4.0",
"jsonpath-rw-ext==1.2.2",
Expand Down

0 comments on commit 8d74d80

Please sign in to comment.