Skip to content

Commit

Permalink
NXDRIVE-2711: Show that upload is still alive for very large files
Browse files Browse the repository at this point in the history
  • Loading branch information
swetayadav1 committed Oct 12, 2023
1 parent 7524f02 commit bd016cd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
7 changes: 4 additions & 3 deletions nxdrive/dao/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2383,9 +2383,10 @@ def update_upload(self, upload: Upload, /) -> None:

def update_upload_requestid(self, upload: Upload, /) -> None:
"""In case of error during linking, update request_uid for upload"""
c = self._get_write_connection().cursor()
sql = "UPDATE Uploads SET request_uid = ? WHERE uid = ?"
c.execute(sql, (upload.request_uid, upload.uid))
with self.lock:
c = self._get_write_connection().cursor()
sql = "UPDATE Uploads SET request_uid = ? WHERE uid = ?"
c.execute(sql, (upload.request_uid, upload.uid))

def pause_transfer(
self,
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import pytest

from nxdrive.client.remote_client import Remote
from nxdrive.client.uploader import BaseUploader
from nxdrive.constants import TransferStatus
from nxdrive.dao.engine import EngineDAO
from nxdrive.dao.manager import ManagerDAO
from nxdrive.engine.engine import Engine
from nxdrive.engine.processor import Processor
from nxdrive.manager import Manager
from nxdrive.objects import DocPair
from nxdrive.objects import DocPair, Upload
from nxdrive.osi import AbstractOSIntegration
from nxdrive.updater.darwin import Updater
from nxdrive.utils import normalized_path
Expand Down Expand Up @@ -141,6 +143,11 @@ def __init__(self, tmp_path):
super().__init__(self, final_app)


class MockUploader(BaseUploader):
def __init__(self, Remote):
super().__init__(self, Remote)


@pytest.fixture()
def engine_dao(tmp_path):
dao = MockEngineDAO
Expand Down Expand Up @@ -188,3 +195,27 @@ def processor(engine, engine_dao):
processor.remote = Remote
processor.dao = engine_dao
return processor


@pytest.fixture()
def baseuploader():
baseuploader = MockUploader
return baseuploader


@pytest.fixture()
def upload():
upload = Upload
upload.path = "/tmp"
upload.status = TransferStatus.ONGOING
upload.engine = f"{engine}"
upload.is_direct_edit = False
upload.is_direct_transfer = True
upload.filesize = "23.0"
upload.batch = {"batchID": f"{str(uuid4())}"}
upload.chunk_size = "345"
upload.remote_parent_path = "/tmp/remote_path"
upload.remote_parent_ref = "/tmp/remote_path_ref"
upload.doc_pair = "test_file"
upload.request_uid = str(uuid4())
return upload
16 changes: 16 additions & 0 deletions tests/unit/test_client_uploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest.mock import Mock
from uuid import uuid4

from nuxeo.models import FileBlob


def test_link_blob_to_doc(baseuploader, upload, tmp_path):
file = tmp_path / f"{uuid4()}.txt"
file.write_bytes(b"content")

baseuploader.dao = Mock()
baseuploader._transfer_autoType_file = Mock()

baseuploader.link_blob_to_doc(
baseuploader, "Filemanager.Import", upload, FileBlob(str(file)), True
)
21 changes: 20 additions & 1 deletion tests/unit/test_engine_dao.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import sqlite3
from datetime import datetime
from multiprocessing import RLock
from pathlib import Path
from unittest.mock import patch
from unittest.mock import Mock, patch
from uuid import uuid4

from nxdrive.constants import TransferStatus
Expand Down Expand Up @@ -608,3 +609,21 @@ def test_migration_interface():
assert not interface.downgrade(cursor)
assert not interface.previous_version
assert not interface.version


def test_update_upload_requestid(engine_dao, upload):
"""Test to save upload and update reuqest_uid of existing row"""
engine_dao.lock = RLock()
with engine_dao("engine_migration_18.db") as dao:
engine_dao.directTransferUpdated = Mock()
# Save New upload
engine_dao.save_upload(dao, upload)

assert upload.uid

previous_request_id = upload.request_uid
upload.request_uid = str(uuid4())
# Update request_uid of existing record
engine_dao.update_upload_requestid(dao, upload)

assert previous_request_id != upload.request_uid

0 comments on commit bd016cd

Please sign in to comment.