e2e: fix for endless apk upload + teardown
This commit is contained in:
parent
9ed68ee7d1
commit
26dcc16ea6
|
@ -396,9 +396,6 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
|
||||||
requests_session = requests.Session()
|
requests_session = requests.Session()
|
||||||
requests_session.auth = (sauce_username, sauce_access_key)
|
requests_session.auth = (sauce_username, sauce_access_key)
|
||||||
try:
|
try:
|
||||||
cls.drivers
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
for _, driver in cls.drivers.items():
|
for _, driver in cls.drivers.items():
|
||||||
session_id = driver.session_id
|
session_id = driver.session_id
|
||||||
try:
|
try:
|
||||||
|
@ -423,8 +420,13 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
|
||||||
continue
|
continue
|
||||||
except (RemoteDisconnected, requests.exceptions.ConnectionError):
|
except (RemoteDisconnected, requests.exceptions.ConnectionError):
|
||||||
pass
|
pass
|
||||||
if cls.loop:
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
cls.loop.close()
|
cls.loop.close()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
for test in test_suite_data.tests:
|
for test in test_suite_data.tests:
|
||||||
github_report.save_test(test)
|
github_report.save_test(test)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import signal
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from contextlib import contextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from http.client import RemoteDisconnected
|
from http.client import RemoteDisconnected
|
||||||
|
@ -203,21 +205,51 @@ def pytest_configure(config):
|
||||||
description='e2e tests are running')
|
description='e2e tests are running')
|
||||||
if config.getoption('env') == 'sauce':
|
if config.getoption('env') == 'sauce':
|
||||||
if not is_uploaded():
|
if not is_uploaded():
|
||||||
|
def _upload_and_check_response(apk_file_path):
|
||||||
|
@contextmanager
|
||||||
|
def _upload_time_limit(seconds):
|
||||||
|
def signal_handler(signum, frame):
|
||||||
|
raise TimeoutError("Apk upload took more than %s seconds" % seconds)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGALRM, signal_handler)
|
||||||
|
signal.alarm(seconds)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
signal.alarm(0)
|
||||||
|
|
||||||
|
with _upload_time_limit(600):
|
||||||
|
class UploadApkException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with open(apk_file_path, 'rb') as f:
|
||||||
|
resp = sauce.storage._session.request('post', '/v1/storage/upload',
|
||||||
|
files={'payload': f})
|
||||||
|
try:
|
||||||
|
if resp['item']['name'] != apk_name:
|
||||||
|
raise UploadApkException(
|
||||||
|
"Incorrect apk was uploaded to Sauce storage, response:\n%s" % resp)
|
||||||
|
except KeyError:
|
||||||
|
raise UploadApkException(
|
||||||
|
"Error when uploading apk to Sauce storage, response:\n%s" % resp)
|
||||||
|
|
||||||
if 'http' in config.getoption('apk'):
|
if 'http' in config.getoption('apk'):
|
||||||
apk_name = config.getoption('apk').split("/")[-1]
|
apk_name = config.getoption('apk').split("/")[-1]
|
||||||
# it works with just a file_name, but I've added full path because not sure how it'll behave on the remote run (Jenkins)
|
# it works with just a file_name, but I've added full path because not sure how it'll behave on the remote run (Jenkins)
|
||||||
file_path = os.path.join(os.path.dirname(__file__), apk_name)
|
file_path, to_remove = os.path.join(os.path.dirname(__file__), apk_name), True
|
||||||
for _ in range(3):
|
|
||||||
try:
|
|
||||||
urllib.request.urlretrieve(config.getoption('apk'),
|
urllib.request.urlretrieve(config.getoption('apk'),
|
||||||
filename=file_path) # if url is not valid it raises an error
|
filename=file_path) # if url is not valid it raises an error
|
||||||
sauce.storage.upload(file_path)
|
else:
|
||||||
os.remove(file_path)
|
file_path, to_remove = config.getoption('apk'), False
|
||||||
|
|
||||||
|
for _ in range(3):
|
||||||
|
try:
|
||||||
|
_upload_and_check_response(apk_file_path=file_path)
|
||||||
break
|
break
|
||||||
except (ConnectionError, RemoteDisconnected):
|
except (ConnectionError, RemoteDisconnected):
|
||||||
sleep(10)
|
sleep(10)
|
||||||
else:
|
if to_remove:
|
||||||
sauce.storage.upload(config.getoption('apk'))
|
os.remove(file_path)
|
||||||
|
|
||||||
|
|
||||||
def pytest_unconfigure(config):
|
def pytest_unconfigure(config):
|
||||||
|
|
Loading…
Reference in New Issue