Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #198 from 2gis/selenium-server-request-timeout
Browse files Browse the repository at this point in the history
Selenium server request timeout
  • Loading branch information
sh0ked authored Mar 21, 2017
2 parents bdba0c7 + 1d1f707 commit 7248fa6
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 301 deletions.
2 changes: 1 addition & 1 deletion config_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Config(object):
OPENASTACK_VM_META_DATA = {
'admin_pass': 'testPassw0rd.'
}
OPENSTACK_VM_USERDATA_FILE_PATH = "%s/userdata" % os.path.abspath(os.curdir)

VM_CREATE_CHECK_PAUSE = 5
VM_CREATE_CHECK_ATTEMPTS = 1000
Expand All @@ -63,4 +64,3 @@ class Config(object):
VMMASTER_AGENT_PORT = 9000

THREAD_POOL_MAX = 100

4 changes: 1 addition & 3 deletions core/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-


SESSION_CLOSE_REASON_API_CALL = "Session closed via API stop_session call"
GET_ENDPOINT_ATTEMPTS = 10
GET_ENDPOINT_WAIT_TIME_INCREMENT = 5

ENDPOINT_REBUILD_ATTEMPTS = 3
REQUEST_TIMEOUT = 120
14 changes: 3 additions & 11 deletions core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class SessionException(Exception):
pass


class ClonesException(Exception):
class CreationException(Exception):
pass


class NoMacError(Exception):
class RequestTimeoutException(Exception):
pass


class CreationException(Exception):
class RequestException(Exception):
pass


Expand All @@ -29,11 +29,3 @@ class TimeoutException(Exception):

class ConnectionError(Exception):
pass


class NoSuchEndpoint(Exception):
pass


class QueueItemNotFound(Exception):
pass
14 changes: 10 additions & 4 deletions core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from datetime import datetime
from flask import current_app

from core import constants
from core.db import models
from core.config import config
from core.exceptions import SessionException
from core.exceptions import SessionException, RequestException, RequestTimeoutException
from core.video import VNCVideoHelper

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -117,6 +118,8 @@ def save_artifacts(self):
artifacts = {
"selenium_server": "/var/log/selenium_server.log"
}
if not self.endpoint_ip:
return False
return self.endpoint.save_artifacts(self, artifacts)

def close(self, reason=None):
Expand Down Expand Up @@ -192,7 +195,7 @@ def add_session_step(self, control_line, body=None, created=None):

return step

def make_request(self, port, request):
def make_request(self, port, request, timeout=constants.REQUEST_TIMEOUT):
""" Make http request to some port in session
and return the response. """

Expand All @@ -206,7 +209,8 @@ def req():
return requests.request(method=request.method,
url=url,
headers=request.headers,
data=request.data)
data=request.data,
timeout=timeout)

t = Thread(target=getresponse, args=(req, q))
t.daemon = True
Expand All @@ -216,8 +220,10 @@ def req():
yield None, None, None

response = q.get()
if isinstance(response, requests.Timeout):
raise RequestTimeoutException("No response for '%s' in %s sec. Original: %s" % (url, timeout, response))
if isinstance(response, Exception):
raise response
raise RequestException("Error for '%s'. Original: %s" % (url, response))

yield response.status_code, response.headers, response.content

Expand Down
2 changes: 0 additions & 2 deletions tests/run_unittests.py

This file was deleted.

1 change: 1 addition & 0 deletions tests/unit/data/config_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Config(object):
OPENASTACK_VM_META_DATA = {
'admin_pass': 'testPassw0rd.'
}
OPENSTACK_VM_USERDATA_FILE_PATH = "%s/tests/unit/data/userdata" % os.path.abspath(os.curdir)

VM_CHECK = False
VM_CHECK_FREQUENCY = 1800
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/data/userdata
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#cloud-config
password: pass
chpasswd: {expire: False}
2 changes: 1 addition & 1 deletion tests/unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ def delete(self):
body = json.loads(response.data)
self.assertEqual(200, body['metacode'])
self.assertEqual("This endpoints were deleted from pool: "
"[%s]" % vm_name_1, body['result'])
"%s" % [vm_name_1], body['result'])
Loading

0 comments on commit 7248fa6

Please sign in to comment.