e2e: fix for endless apk upload + teardown

This commit is contained in:
Yevheniia Berdnyk 2023-07-06 17:47:35 +03:00
parent 9ed68ee7d1
commit 26dcc16ea6
No known key found for this signature in database
GPG Key ID: 0642C73C66214825
2 changed files with 70 additions and 36 deletions

View File

@ -396,9 +396,6 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
requests_session = requests.Session()
requests_session.auth = (sauce_username, sauce_access_key)
try:
cls.drivers
except AttributeError:
pass
for _, driver in cls.drivers.items():
session_id = driver.session_id
try:
@ -423,8 +420,13 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
continue
except (RemoteDisconnected, requests.exceptions.ConnectionError):
pass
if cls.loop:
except AttributeError:
pass
finally:
try:
cls.loop.close()
except AttributeError:
pass
for test in test_suite_data.tests:
github_report.save_test(test)

View File

@ -1,6 +1,8 @@
import os
import re
import signal
import urllib.request
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import datetime
from http.client import RemoteDisconnected
@ -203,21 +205,51 @@ def pytest_configure(config):
description='e2e tests are running')
if config.getoption('env') == 'sauce':
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'):
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)
file_path = os.path.join(os.path.dirname(__file__), apk_name)
for _ in range(3):
try:
file_path, to_remove = os.path.join(os.path.dirname(__file__), apk_name), True
urllib.request.urlretrieve(config.getoption('apk'),
filename=file_path) # if url is not valid it raises an error
sauce.storage.upload(file_path)
os.remove(file_path)
else:
file_path, to_remove = config.getoption('apk'), False
for _ in range(3):
try:
_upload_and_check_response(apk_file_path=file_path)
break
except (ConnectionError, RemoteDisconnected):
sleep(10)
else:
sauce.storage.upload(config.getoption('apk'))
if to_remove:
os.remove(file_path)
def pytest_unconfigure(config):