|
|
|
@ -1,3 +1,4 @@ |
|
|
|
|
# ruff: noqa: TID251 |
|
|
|
|
import pytest |
|
|
|
|
from functools import wraps |
|
|
|
|
import json |
|
|
|
@ -190,11 +191,11 @@ class TestAthenadMethods: |
|
|
|
|
fn = self._create_file('qlog', data=os.urandom(10000 * 1024)) |
|
|
|
|
|
|
|
|
|
upload_fn = fn + ('.zst' if compress else '') |
|
|
|
|
item = athenad.UploadItem(path=upload_fn, url="http://localhost:1238", headers={}, created_at=int(time.time()*1000), id='') # noqa: TID251 |
|
|
|
|
item = athenad.UploadItem(path=upload_fn, url="http://localhost:1238", headers={}, created_at=int(time.time()*1000), id='') |
|
|
|
|
with pytest.raises(requests.exceptions.ConnectionError): |
|
|
|
|
athenad._do_upload(item) |
|
|
|
|
|
|
|
|
|
item = athenad.UploadItem(path=upload_fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='') # noqa: TID251 |
|
|
|
|
item = athenad.UploadItem(path=upload_fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='') |
|
|
|
|
resp = athenad._do_upload(item) |
|
|
|
|
assert resp.status_code == 201 |
|
|
|
|
|
|
|
|
@ -226,7 +227,7 @@ class TestAthenadMethods: |
|
|
|
|
@with_upload_handler |
|
|
|
|
def test_upload_handler(self, host): |
|
|
|
|
fn = self._create_file('qlog.zst') |
|
|
|
|
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) # noqa: TID251 |
|
|
|
|
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) |
|
|
|
|
|
|
|
|
|
athenad.upload_queue.put_nowait(item) |
|
|
|
|
self._wait_for_upload() |
|
|
|
@ -242,7 +243,7 @@ class TestAthenadMethods: |
|
|
|
|
mock_put = mocker.patch('openpilot.system.athena.athenad.UPLOAD_SESS.put') |
|
|
|
|
mock_put.return_value.__enter__.return_value.status_code = status |
|
|
|
|
fn = self._create_file('qlog.zst') |
|
|
|
|
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) # noqa: TID251 |
|
|
|
|
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) |
|
|
|
|
|
|
|
|
|
athenad.upload_queue.put_nowait(item) |
|
|
|
|
self._wait_for_upload() |
|
|
|
@ -257,7 +258,7 @@ class TestAthenadMethods: |
|
|
|
|
def test_upload_handler_timeout(self): |
|
|
|
|
"""When an upload times out or fails to connect it should be placed back in the queue""" |
|
|
|
|
fn = self._create_file('qlog.zst') |
|
|
|
|
item = athenad.UploadItem(path=fn, url="http://localhost:44444/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) # noqa: TID251 |
|
|
|
|
item = athenad.UploadItem(path=fn, url="http://localhost:44444/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) |
|
|
|
|
item_no_retry = replace(item, retry_count=MAX_RETRY_COUNT) |
|
|
|
|
|
|
|
|
|
athenad.upload_queue.put_nowait(item_no_retry) |
|
|
|
@ -278,7 +279,7 @@ class TestAthenadMethods: |
|
|
|
|
@with_upload_handler |
|
|
|
|
def test_cancel_upload(self): |
|
|
|
|
item = athenad.UploadItem(path="qlog.zst", url="http://localhost:44444/qlog.zst", headers={}, |
|
|
|
|
created_at=int(time.time()*1000), id='id', allow_cellular=True) # noqa: TID251 |
|
|
|
|
created_at=int(time.time()*1000), id='id', allow_cellular=True) |
|
|
|
|
athenad.upload_queue.put_nowait(item) |
|
|
|
|
dispatcher["cancelUpload"](item.id) |
|
|
|
|
|
|
|
|
@ -312,7 +313,7 @@ class TestAthenadMethods: |
|
|
|
|
@with_upload_handler |
|
|
|
|
def test_list_upload_queue_current(self, host: str): |
|
|
|
|
fn = self._create_file('qlog.zst') |
|
|
|
|
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) # noqa: TID251 |
|
|
|
|
item = athenad.UploadItem(path=fn, url=f"{host}/qlog.zst", headers={}, created_at=int(time.time()*1000), id='', allow_cellular=True) |
|
|
|
|
|
|
|
|
|
athenad.upload_queue.put_nowait(item) |
|
|
|
|
self._wait_for_upload() |
|
|
|
@ -331,7 +332,7 @@ class TestAthenadMethods: |
|
|
|
|
path=fp, |
|
|
|
|
url=f"http://localhost:44444/{fn}", |
|
|
|
|
headers={}, |
|
|
|
|
created_at=int(time.time()*1000), # noqa: TID251 |
|
|
|
|
created_at=int(time.time()*1000), |
|
|
|
|
id='', |
|
|
|
|
allow_cellular=True, |
|
|
|
|
priority=i |
|
|
|
@ -343,7 +344,7 @@ class TestAthenadMethods: |
|
|
|
|
|
|
|
|
|
def test_list_upload_queue(self): |
|
|
|
|
item = athenad.UploadItem(path="qlog.zst", url="http://localhost:44444/qlog.zst", headers={}, |
|
|
|
|
created_at=int(time.time()*1000), id='id', allow_cellular=True) # noqa: TID251 |
|
|
|
|
created_at=int(time.time()*1000), id='id', allow_cellular=True) |
|
|
|
|
athenad.upload_queue.put_nowait(item) |
|
|
|
|
|
|
|
|
|
items = dispatcher["listUploadQueue"]() |
|
|
|
@ -356,8 +357,8 @@ class TestAthenadMethods: |
|
|
|
|
assert len(items) == 0 |
|
|
|
|
|
|
|
|
|
def test_upload_queue_persistence(self): |
|
|
|
|
item1 = athenad.UploadItem(path="_", url="_", headers={}, created_at=int(time.time()), id='id1') # noqa: TID251 |
|
|
|
|
item2 = athenad.UploadItem(path="_", url="_", headers={}, created_at=int(time.time()), id='id2') # noqa: TID251 |
|
|
|
|
item1 = athenad.UploadItem(path="_", url="_", headers={}, created_at=int(time.time()), id='id1') |
|
|
|
|
item2 = athenad.UploadItem(path="_", url="_", headers={}, created_at=int(time.time()), id='id2') |
|
|
|
|
|
|
|
|
|
athenad.upload_queue.put_nowait(item1) |
|
|
|
|
athenad.upload_queue.put_nowait(item2) |
|
|
|
|