File: testuploadreset.cpp

package info (click to toggle)
nextcloud-desktop 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,404 kB
  • sloc: cpp: 118,401; objc: 752; python: 606; sh: 395; ansic: 391; ruby: 174; makefile: 44; javascript: 32; xml: 6
file content (86 lines) | stat: -rw-r--r-- 3,021 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2017 ownCloud, Inc.
 * SPDX-License-Identifier: CC0-1.0
 * 
 * This software is in the public domain, furnished "as is", without technical
 * support, and with no warranty, express or implied, as to its usefulness for
 * any purpose.
 */

#include <QtTest>
#include "syncenginetestutils.h"
#include <syncengine.h>
#include <common/syncjournaldb.h>

using namespace OCC;

class TestUploadReset : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase()
    {
        OCC::Logger::instance()->setLogFlush(true);
        OCC::Logger::instance()->setLogDebug(true);

        QStandardPaths::setTestModeEnabled(true);
    }

    // Verify that the chunked transfer eventually gets reset with the new chunking
    void testFileUploadNg() {
        FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};

        fakeFolder.syncEngine().account()->setCapabilities({ { "dav", QVariantMap{
                {"chunking", "1.0"},
                {"httpErrorCodesThatResetFailingChunkedUploads", QVariantList{500} } } } });

        const auto size = 200LL * 1024LL * 1024LL; // 200 MiB
        fakeFolder.localModifier().insert("A/a0", size);
        QDateTime modTime = QDateTime::currentDateTime();
        fakeFolder.localModifier().setModTime("A/a0", modTime);

        // Create a transfer id, so we can make the final MOVE fail
        SyncJournalDb::UploadInfo uploadInfo;
        uploadInfo._transferid = 1;
        uploadInfo._valid = true;
        uploadInfo._modtime = Utility::qDateTimeToTime_t(modTime);
        uploadInfo._size = size;
        fakeFolder.syncEngine().journal()->setUploadInfo("A/a0", uploadInfo);

        fakeFolder.uploadState().mkdir("1");
        fakeFolder.serverErrorPaths().append("1/.file");

        QVERIFY(!fakeFolder.syncOnce());

        uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0");
        QCOMPARE(uploadInfo._errorCount, 1);
        QCOMPARE(uploadInfo._transferid, 1U);

        QVERIFY(fakeFolder.syncEngine().journal()->wipeErrorBlacklist());
        QVERIFY(!fakeFolder.syncOnce());

        uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0");
        QCOMPARE(uploadInfo._errorCount, 2);
        QCOMPARE(uploadInfo._transferid, 1U);

        QVERIFY(fakeFolder.syncEngine().journal()->wipeErrorBlacklist());
        QVERIFY(!fakeFolder.syncOnce());

        uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0");
        QCOMPARE(uploadInfo._errorCount, 3);
        QCOMPARE(uploadInfo._transferid, 1U);

        QVERIFY(fakeFolder.syncEngine().journal()->wipeErrorBlacklist());
        QVERIFY(!fakeFolder.syncOnce());

        uploadInfo = fakeFolder.syncEngine().journal()->getUploadInfo("A/a0");
        QCOMPARE(uploadInfo._errorCount, 0);
        QCOMPARE(uploadInfo._transferid, 0U);
        QVERIFY(!uploadInfo._valid);
    }
};

QTEST_GUILESS_MAIN(TestUploadReset)
#include "testuploadreset.moc"