From b840fe9cb695a7af26add34cfa95c964ccaba87e Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Fri, 3 Jan 2025 11:56:20 +0100 Subject: [PATCH 1/8] Prevent name collision in RemoteTemporaryDirectory --- src/libsyncengine/jobs/abstractjob.h | 2 +- .../executor/testexecutorworker.cpp | 14 ----- .../test_utility/remotetemporarydirectory.cpp | 53 ++++++++++++------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/libsyncengine/jobs/abstractjob.h b/src/libsyncengine/jobs/abstractjob.h index ecaa76535..536655164 100644 --- a/src/libsyncengine/jobs/abstractjob.h +++ b/src/libsyncengine/jobs/abstractjob.h @@ -49,7 +49,7 @@ class AbstractJob : public Poco::Runnable { inline void setProgressPercentCallback(const std::function &newCallback) { _progressPercentCallback = newCallback; } - + inline ExitInfo exitInfo() const { return ExitInfo(_exitCode, _exitCause); } inline ExitCode exitCode() const { return _exitCode; } inline ExitCause exitCause() const { return _exitCause; } diff --git a/test/libsyncengine/propagation/executor/testexecutorworker.cpp b/test/libsyncengine/propagation/executor/testexecutorworker.cpp index e05200e4e..3da34e801 100644 --- a/test/libsyncengine/propagation/executor/testexecutorworker.cpp +++ b/test/libsyncengine/propagation/executor/testexecutorworker.cpp @@ -258,20 +258,6 @@ void TestExecutorWorker::testIsValidDestination() { const auto root = _syncPal->updateTree(ReplicaSide::Remote)->rootNode(); - // False if the item created on the local replica is not at the root of the synchronisation folder and has a - // corresponding parent node with no id. - { - const auto correspondingParentNode = std::make_shared( - 666, ReplicaSide::Remote, Str("parent_dir"), NodeType::Directory, OperationType::None, std::nullopt, - testhelpers::defaultTime, testhelpers::defaultTime, testhelpers::defaultFileSize, root); - - - SyncOpPtr op = generateSyncOperationWithNestedNodes(1, Str("test_file.txt"), OperationType::Create, NodeType::File); - executorWorkerMock->setCorrespondingNodeInOtherTree({{op->affectedNode()->parentNode(), correspondingParentNode}}); - op->setTargetSide(ReplicaSide::Remote); - CPPUNIT_ASSERT(!executorWorkerMock->isValidDestination(op)); - } - const auto correspondingParentCommonDocsNode = std::make_shared( 666, ReplicaSide::Remote, Utility::commonDocumentsFolderName(), NodeType::Directory, OperationType::None, "common_docs_id", testhelpers::defaultTime, testhelpers::defaultTime, testhelpers::defaultFileSize, root); diff --git a/test/test_utility/remotetemporarydirectory.cpp b/test/test_utility/remotetemporarydirectory.cpp index dafd2a6f1..64a715772 100644 --- a/test/test_utility/remotetemporarydirectory.cpp +++ b/test/test_utility/remotetemporarydirectory.cpp @@ -23,28 +23,45 @@ #include "../../src/libsyncengine/jobs/network/API_v2/deletejob.h" #include "libsyncengine/jobs/network/networkjobsparams.h" #include "libcommonserver/utility/utility.h" +#include "libcommon/utility/utility.h" namespace KDC { RemoteTemporaryDirectory::RemoteTemporaryDirectory(int driveDbId, const NodeId& parentId, - const std::string& testType /*= "undef"*/) : _driveDbId(driveDbId) { - // Generate directory name - const std::time_t now = std::time(nullptr); - const std::tm tm = *std::localtime(&now); - std::ostringstream woss; - woss << std::put_time(&tm, "%Y%m%d_%H%M"); - - _dirName = Str("kdrive_") + Str2SyncName(testType) + Str("_unit_tests_") + Str2SyncName(woss.str()); - - // Create remote test dir - CreateDirJob job(_driveDbId, parentId, _dirName); - CPPUNIT_ASSERT_EQUAL(ExitCode::Ok, job.runSynchronously()); - - // Extract file ID - CPPUNIT_ASSERT(job.jsonRes()); - Poco::JSON::Object::Ptr dataObj = job.jsonRes()->getObject(dataKey); - CPPUNIT_ASSERT(dataObj); - _dirId = dataObj->get(idKey).toString(); + const std::string& testType /*= "undef"*/) : + _driveDbId(driveDbId) { + std::string suffix = CommonUtility::generateRandomStringAlphaNum(5); + int retry = 5; + do { + // Generate directory name + const std::time_t now = std::time(nullptr); + const std::tm tm = *std::localtime(&now); + std::ostringstream woss; + woss << std::put_time(&tm, "%Y%m%d_%H%M"); + _dirName = Str("kdrive_") + Str2SyncName(testType) + Str("_unit_tests_") + Str2SyncName(woss.str() + "___" + suffix); + + // Create remote test dir + CreateDirJob job(_driveDbId, parentId, _dirName); + job.runSynchronously(); + if (job.exitInfo() == ExitInfo::ExitInfo(ExitCode::BackError, ExitCause::FileAlreadyExist) && retry > 0) { + suffix = CommonUtility::generateRandomStringAlphaNum(5); + retry--; + continue; + } + + CPPUNIT_ASSERT_EQUAL(ExitInfo(ExitCode::Ok), job.exitInfo()); + + // Extract file ID + CPPUNIT_ASSERT(job.jsonRes()); + Poco::JSON::Object::Ptr dataObj = job.jsonRes()->getObject(dataKey); + CPPUNIT_ASSERT(dataObj); + _dirId = dataObj->get(idKey).toString(); + LOGW_INFO(Log::instance()->getLogger(), L"RemoteTemporaryDirectory created: " << Utility::formatSyncName(_dirName) + << L" with ID: " + << Utility::s2ws(_dirId)); + break; + } while (true); } + RemoteTemporaryDirectory::~RemoteTemporaryDirectory() { if (_isDeleted) return; From 8dfe487e62a55eafe5b3322276e48a02aed78042 Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Fri, 3 Jan 2025 11:59:17 +0100 Subject: [PATCH 2/8] Revert TestExecutorWorker change. --- .../propagation/executor/testexecutorworker.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/libsyncengine/propagation/executor/testexecutorworker.cpp b/test/libsyncengine/propagation/executor/testexecutorworker.cpp index 3da34e801..e05200e4e 100644 --- a/test/libsyncengine/propagation/executor/testexecutorworker.cpp +++ b/test/libsyncengine/propagation/executor/testexecutorworker.cpp @@ -258,6 +258,20 @@ void TestExecutorWorker::testIsValidDestination() { const auto root = _syncPal->updateTree(ReplicaSide::Remote)->rootNode(); + // False if the item created on the local replica is not at the root of the synchronisation folder and has a + // corresponding parent node with no id. + { + const auto correspondingParentNode = std::make_shared( + 666, ReplicaSide::Remote, Str("parent_dir"), NodeType::Directory, OperationType::None, std::nullopt, + testhelpers::defaultTime, testhelpers::defaultTime, testhelpers::defaultFileSize, root); + + + SyncOpPtr op = generateSyncOperationWithNestedNodes(1, Str("test_file.txt"), OperationType::Create, NodeType::File); + executorWorkerMock->setCorrespondingNodeInOtherTree({{op->affectedNode()->parentNode(), correspondingParentNode}}); + op->setTargetSide(ReplicaSide::Remote); + CPPUNIT_ASSERT(!executorWorkerMock->isValidDestination(op)); + } + const auto correspondingParentCommonDocsNode = std::make_shared( 666, ReplicaSide::Remote, Utility::commonDocumentsFolderName(), NodeType::Directory, OperationType::None, "common_docs_id", testhelpers::defaultTime, testhelpers::defaultTime, testhelpers::defaultFileSize, root); From 58d00cac95faf7334d8c0947e05182179e7e7a76 Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Fri, 3 Jan 2025 14:37:07 +0100 Subject: [PATCH 3/8] Fix TestJobManager::testCancelJobs random faillure. --- test/libsyncengine/jobs/testjobmanager.cpp | 40 ++++++++++++------- .../test_utility/remotetemporarydirectory.cpp | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/test/libsyncengine/jobs/testjobmanager.cpp b/test/libsyncengine/jobs/testjobmanager.cpp index 9b6db9a1e..e27f3750f 100644 --- a/test/libsyncengine/jobs/testjobmanager.cpp +++ b/test/libsyncengine/jobs/testjobmanager.cpp @@ -43,7 +43,6 @@ namespace KDC { static const SyncPath localTestDirPath(std::wstring(L"" TEST_DIR) + L"/test_ci"); static const SyncPath localTestDirPath_manyFiles(std::wstring(L"" TEST_DIR) + L"/test_ci/many_files_dir"); static const SyncPath localTestDirPath_pictures(std::wstring(L"" TEST_DIR) + L"/test_ci/test_pictures"); -static const SyncPath localTestDirPath_bigFiles(std::wstring(L"" TEST_DIR) + L"/test_ci/big_file_dir"); static const int driveDbId = 1; void KDC::TestJobManager::setUp() { const testhelpers::TestVariables testVariables; @@ -175,25 +174,40 @@ void TestJobManager::testWithCallbackBigFiles() { } void TestJobManager::testCancelJobs() { - // Create temp remote directory const RemoteTemporaryDirectory remoteTmpDir(driveDbId, _testVariables.remoteDirId, "TestJobManager testCancelJobs"); + const LocalTemporaryDirectory localTmpDir("testJobManager"); + const int localFileCounter = 100; + for (int i = 0; i < localFileCounter; i++) { + testhelpers::generateOrEditTestFile(localTmpDir.path() / ("file_" + std::to_string(i) + ".txt")); + } + // Upload all files in testDir - ulong jobCounter = 0; - for (auto &dirEntry: std::filesystem::directory_iterator(localTestDirPath_manyFiles)) { + for (auto &dirEntry: std::filesystem::directory_iterator(localTmpDir.path())) { auto job = std::make_shared(driveDbId, dirEntry.path(), dirEntry.path().filename().native(), remoteTmpDir.id(), 0); std::function callback = std::bind(&TestJobManager::callback, this, std::placeholders::_1); JobManager::instance()->queueAsyncJob(job, Poco::Thread::PRIO_NORMAL, callback); - jobCounter++; const std::scoped_lock lock(_mutex); _ongoingJobs.try_emplace(static_cast(job->jobId()), job); } - - Utility::msleep(1000); // Wait 1sec + while (_ongoingJobs.size() == localFileCounter) { + Utility::msleep(1); // Wait 1ms + } cancelAllOngoingJobs(); - Utility::msleep(10000); // Wait 10sec + int rerty = 1000; // Wait max 10sec + while ((!JobManager::_managedJobs.empty() || !JobManager::_queuedJobs.empty() || !JobManager::_runningJobs.empty() || + !JobManager::_pendingJobs.empty()) && + (rerty > 0)) { + rerty--; + Utility::msleep(10); + } + + CPPUNIT_ASSERT(JobManager::instance()->_managedJobs.empty()); + CPPUNIT_ASSERT(JobManager::instance()->_queuedJobs.empty()); + CPPUNIT_ASSERT(JobManager::instance()->_runningJobs.empty()); + CPPUNIT_ASSERT(JobManager::instance()->_pendingJobs.empty()); GetFileListJob fileListJob(driveDbId, remoteTmpDir.id()); fileListJob.runSynchronously(); @@ -202,14 +216,10 @@ void TestJobManager::testCancelJobs() { CPPUNIT_ASSERT(resObj); Poco::JSON::Array::Ptr data = resObj->getArray(dataKey); - size_t total = data->size(); - CPPUNIT_ASSERT(jobCounter != total); - CPPUNIT_ASSERT(total > 0); + size_t uploadedFileCounter = data->size(); + CPPUNIT_ASSERT(localFileCounter != uploadedFileCounter); + CPPUNIT_ASSERT(uploadedFileCounter > 0); CPPUNIT_ASSERT(ongoingJobsCount() == 0); - CPPUNIT_ASSERT(JobManager::instance()->_managedJobs.empty()); - CPPUNIT_ASSERT(JobManager::instance()->_queuedJobs.empty()); - CPPUNIT_ASSERT(JobManager::instance()->_runningJobs.empty()); - CPPUNIT_ASSERT(JobManager::instance()->_pendingJobs.empty()); } std::queue finishedJobs; diff --git a/test/test_utility/remotetemporarydirectory.cpp b/test/test_utility/remotetemporarydirectory.cpp index 64a715772..c08ada9a5 100644 --- a/test/test_utility/remotetemporarydirectory.cpp +++ b/test/test_utility/remotetemporarydirectory.cpp @@ -42,7 +42,7 @@ RemoteTemporaryDirectory::RemoteTemporaryDirectory(int driveDbId, const NodeId& // Create remote test dir CreateDirJob job(_driveDbId, parentId, _dirName); job.runSynchronously(); - if (job.exitInfo() == ExitInfo::ExitInfo(ExitCode::BackError, ExitCause::FileAlreadyExist) && retry > 0) { + if (job.exitInfo() == ExitInfo(ExitCode::BackError, ExitCause::FileAlreadyExist) && retry > 0) { suffix = CommonUtility::generateRandomStringAlphaNum(5); retry--; continue; From 5e8b9307544bc714e585ede3b2c00973d3f7ca30 Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Fri, 3 Jan 2025 15:15:50 +0100 Subject: [PATCH 4/8] Fix testLog --- test/libcommonserver/log/testlog.cpp | 37 ++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/test/libcommonserver/log/testlog.cpp b/test/libcommonserver/log/testlog.cpp index fc65aafe8..f307f4db6 100644 --- a/test/libcommonserver/log/testlog.cpp +++ b/test/libcommonserver/log/testlog.cpp @@ -91,28 +91,37 @@ void TestLog::testExpiredLogFiles(void) { // This test checks that old archived log files are deleted after a certain time clearLogDirectory(); - // Generate a fake log file + // Generate a fake old log file std::ofstream fakeLogFile(_logDir / APPLICATION_NAME "_fake.log.gz"); fakeLogFile << "Fake old log file" << std::endl; fakeLogFile.close(); - LOG_INFO(_logger, "Test log file expiration"); // Ensure the log file is created. - CPPUNIT_ASSERT_EQUAL(2, countFilesInDirectory(_logDir)); // The current log file and the fake archived log file. + // Ensure that a new log file is created + LOG_INFO(_logger, "Test log file expiration"); + // Check that we got 2 log files (the current one and the fake old one) + CPPUNIT_ASSERT_EQUAL(2, countFilesInDirectory(_logDir)); + + // Set the expiration time to 2 seconds auto *appender = static_cast(_logger.getAppender(Log::rfName).get()); appender->setExpire(2); // 2 seconds - Utility::msleep(1000); - appender->checkForExpiredFiles(); - - const auto now = std::chrono::system_clock::now(); - KDC::testhelpers::setModificationDate(Log::instance()->getLogFilePath(), now); - CPPUNIT_ASSERT_EQUAL(2, countFilesInDirectory(_logDir)); // The fake log file should not be deleted yet (< 2 seconds). - - Utility::msleep(1000); - appender->checkForExpiredFiles(); + const auto start = std::chrono::system_clock::now(); + auto now = std::chrono::system_clock::now(); + while (now - start < std::chrono::seconds(3)) { + now = std::chrono::system_clock::now(); + KDC::testhelpers::setModificationDate(Log::instance()->getLogFilePath(), + now); // Prevent the current log file from being deleted. + appender->checkForExpiredFiles(); + if (now - start < std::chrono::milliseconds(1500)) { // The fake log file should not be deleted yet. + CPPUNIT_ASSERT_EQUAL(2, countFilesInDirectory(_logDir)); + } else if (countFilesInDirectory(_logDir) == 1) { // The fake log file MIGHT be deleted now. + break; + } + Utility::msleep(500); + } - CPPUNIT_ASSERT_EQUAL(1, countFilesInDirectory(_logDir)); // The fake log file should be deleted now. + CPPUNIT_ASSERT_EQUAL(1, countFilesInDirectory(_logDir)); // The fake log file SHOULD be deleted now. appender->setExpire(CommonUtility::logsPurgeRate * 24 * 3600); } @@ -145,6 +154,8 @@ void TestLog::clearLogDirectory(void) const { continue; } IoHelper::deleteItem(entry.path(), ioError); + CPPUNIT_ASSERT_EQUAL(IoError::Success, ioError); + } CPPUNIT_ASSERT_EQUAL(IoError::Success, ioError); CPPUNIT_ASSERT(endOfDirectory); From 8b24d312ec4538b65bf908d8c904f031bd7208dd Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Mon, 6 Jan 2025 10:48:24 +0100 Subject: [PATCH 5/8] Adress PR comment. --- test/libsyncengine/jobs/testjobmanager.cpp | 8 ++++---- test/test_utility/remotetemporarydirectory.cpp | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/test/libsyncengine/jobs/testjobmanager.cpp b/test/libsyncengine/jobs/testjobmanager.cpp index e27f3750f..6f28c60d1 100644 --- a/test/libsyncengine/jobs/testjobmanager.cpp +++ b/test/libsyncengine/jobs/testjobmanager.cpp @@ -196,11 +196,11 @@ void TestJobManager::testCancelJobs() { cancelAllOngoingJobs(); - int rerty = 1000; // Wait max 10sec + int retry = 1000; // Wait max 10sec while ((!JobManager::_managedJobs.empty() || !JobManager::_queuedJobs.empty() || !JobManager::_runningJobs.empty() || !JobManager::_pendingJobs.empty()) && - (rerty > 0)) { - rerty--; + (retry > 0)) { + retry--; Utility::msleep(10); } @@ -216,7 +216,7 @@ void TestJobManager::testCancelJobs() { CPPUNIT_ASSERT(resObj); Poco::JSON::Array::Ptr data = resObj->getArray(dataKey); - size_t uploadedFileCounter = data->size(); + const size_t uploadedFileCounter = data->size(); CPPUNIT_ASSERT(localFileCounter != uploadedFileCounter); CPPUNIT_ASSERT(uploadedFileCounter > 0); CPPUNIT_ASSERT(ongoingJobsCount() == 0); diff --git a/test/test_utility/remotetemporarydirectory.cpp b/test/test_utility/remotetemporarydirectory.cpp index c08ada9a5..43eea5f07 100644 --- a/test/test_utility/remotetemporarydirectory.cpp +++ b/test/test_utility/remotetemporarydirectory.cpp @@ -29,9 +29,9 @@ namespace KDC { RemoteTemporaryDirectory::RemoteTemporaryDirectory(int driveDbId, const NodeId& parentId, const std::string& testType /*= "undef"*/) : _driveDbId(driveDbId) { - std::string suffix = CommonUtility::generateRandomStringAlphaNum(5); int retry = 5; do { + std::string suffix = CommonUtility::generateRandomStringAlphaNum(5); // Generate directory name const std::time_t now = std::time(nullptr); const std::tm tm = *std::localtime(&now); @@ -43,7 +43,6 @@ RemoteTemporaryDirectory::RemoteTemporaryDirectory(int driveDbId, const NodeId& CreateDirJob job(_driveDbId, parentId, _dirName); job.runSynchronously(); if (job.exitInfo() == ExitInfo(ExitCode::BackError, ExitCause::FileAlreadyExist) && retry > 0) { - suffix = CommonUtility::generateRandomStringAlphaNum(5); retry--; continue; } @@ -56,8 +55,7 @@ RemoteTemporaryDirectory::RemoteTemporaryDirectory(int driveDbId, const NodeId& CPPUNIT_ASSERT(dataObj); _dirId = dataObj->get(idKey).toString(); LOGW_INFO(Log::instance()->getLogger(), L"RemoteTemporaryDirectory created: " << Utility::formatSyncName(_dirName) - << L" with ID: " - << Utility::s2ws(_dirId)); + << L" with ID: " << Utility::s2ws(_dirId)); break; } while (true); } From 14e75c74fbd9a4f2e65e1a20757434822c254458 Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Wed, 8 Jan 2025 16:15:55 +0100 Subject: [PATCH 6/8] Clarify assert in RemoteTemporaryDirectory --- test/test_utility/remotetemporarydirectory.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_utility/remotetemporarydirectory.cpp b/test/test_utility/remotetemporarydirectory.cpp index 43eea5f07..1664cb0af 100644 --- a/test/test_utility/remotetemporarydirectory.cpp +++ b/test/test_utility/remotetemporarydirectory.cpp @@ -47,12 +47,13 @@ RemoteTemporaryDirectory::RemoteTemporaryDirectory(int driveDbId, const NodeId& continue; } - CPPUNIT_ASSERT_EQUAL(ExitInfo(ExitCode::Ok), job.exitInfo()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("RemoteTemporaryDirectory() failed to create the directory on remote side.", + ExitInfo(ExitCode::Ok), job.exitInfo()); // Extract file ID - CPPUNIT_ASSERT(job.jsonRes()); + CPPUNIT_ASSERT_MESSAGE("RemoteTemporaryDirectory() Failed to extract the file id.", job.jsonRes()); Poco::JSON::Object::Ptr dataObj = job.jsonRes()->getObject(dataKey); - CPPUNIT_ASSERT(dataObj); + CPPUNIT_ASSERT_MESSAGE("RemoteTemporaryDirectory() Failed to extract the file id (2).", dataObj); _dirId = dataObj->get(idKey).toString(); LOGW_INFO(Log::instance()->getLogger(), L"RemoteTemporaryDirectory created: " << Utility::formatSyncName(_dirName) << L" with ID: " << Utility::s2ws(_dirId)); From 25317a8cba66baaf4416117204ba2879f7ca59c4 Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Thu, 9 Jan 2025 10:10:43 +0100 Subject: [PATCH 7/8] Ensure that all jobs ends before cheking dir size in TestJobManager::testWithoutCallback --- test/libsyncengine/jobs/testjobmanager.cpp | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/test/libsyncengine/jobs/testjobmanager.cpp b/test/libsyncengine/jobs/testjobmanager.cpp index 6f28c60d1..a0ba53708 100644 --- a/test/libsyncengine/jobs/testjobmanager.cpp +++ b/test/libsyncengine/jobs/testjobmanager.cpp @@ -90,21 +90,39 @@ void KDC::TestJobManager::tearDown() { void TestJobManager::testWithoutCallback() { // Create temp remote directory const RemoteTemporaryDirectory remoteTmpDir(driveDbId, _testVariables.remoteDirId, "TestJobManager testWithoutCallback"); + const LocalTemporaryDirectory localTmpDir("TestJobManager testWithoutCallback"); + for (int i = 0; i < 100; i++) { + testhelpers::generateOrEditTestFile(localTmpDir.path() / ("file_" + std::to_string(i) + ".txt")); + } // Upload all files in testDir size_t counter = 0; - for (auto &dirEntry: std::filesystem::directory_iterator(localTestDirPath_manyFiles)) { + std::queue jobIds; + for (auto &dirEntry: std::filesystem::directory_iterator(localTmpDir.path())) { if (dirEntry.path().filename() == ".DS_Store") { continue; } - std::shared_ptr job = std::make_shared(driveDbId, dirEntry.path(), + auto job = std::make_shared(driveDbId, dirEntry.path(), dirEntry.path().filename().native(), remoteTmpDir.id(), 0); JobManager::instance()->queueAsyncJob(job); + jobIds.push(job->jobId()); counter++; } - Utility::msleep(10000); // Wait 10sec + // Wait for all uploads to finish + const auto start = std::chrono::steady_clock::now(); + while (!jobIds.empty()) { + const auto now = std::chrono::steady_clock::now(); + CPPUNIT_ASSERT_MESSAGE("All uploads have not finished in 30 seconds", + std::chrono::duration_cast(now - start).count() < 30); + Utility::msleep(100); // Wait 100ms + UniqueId jobId = jobIds.front(); + while (jobId != -1 && JobManager::instance()->isJobFinished(jobId)) { + jobIds.pop(); + jobId = jobIds.empty() ? -1 : jobIds.front(); + } + } GetFileListJob fileListJob(driveDbId, remoteTmpDir.id()); fileListJob.runSynchronously(); @@ -139,7 +157,7 @@ void TestJobManager::testWithCallback() { _ongoingJobs.insert({job->jobId(), job}); } - int waitCountMax = 100; // Wait max 10sec + int waitCountMax = 300; // Wait max 30sec while (ongoingJobsCount() > 0 && waitCountMax-- > 0 && !_jobErrorSocketsDefuncted && !_jobErrorOther) { Utility::msleep(100); // Wait 100ms } From f8773e449234c11f5bb4c8563fe62cd30f9c9982 Mon Sep 17 00:00:00 2001 From: Herve Eruam Date: Fri, 10 Jan 2025 07:59:33 +0100 Subject: [PATCH 8/8] Code simplification in TestJobManager::testWithoutCallback() --- test/libsyncengine/jobs/testjobmanager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/libsyncengine/jobs/testjobmanager.cpp b/test/libsyncengine/jobs/testjobmanager.cpp index a0ba53708..fcc233f9d 100644 --- a/test/libsyncengine/jobs/testjobmanager.cpp +++ b/test/libsyncengine/jobs/testjobmanager.cpp @@ -116,11 +116,10 @@ void TestJobManager::testWithoutCallback() { const auto now = std::chrono::steady_clock::now(); CPPUNIT_ASSERT_MESSAGE("All uploads have not finished in 30 seconds", std::chrono::duration_cast(now - start).count() < 30); + Utility::msleep(100); // Wait 100ms - UniqueId jobId = jobIds.front(); - while (jobId != -1 && JobManager::instance()->isJobFinished(jobId)) { + while (!jobIds.empty() && JobManager::instance()->isJobFinished(jobIds.front())) { jobIds.pop(); - jobId = jobIds.empty() ? -1 : jobIds.front(); } }