Skip to content
Snippets Groups Projects
Commit 505a0262 authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

do not use async in tests

parent 9deb5db1
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,9 @@ void FolderToDbImporter::ProcessNextChunk(const FileInfos& file_list,
p->next_chunk_size = p->chunk + (p->remainder ? 1 : 0);
if (p->next_chunk_size == 0) return;
res->push_back(std::async(std::launch::async, &FolderToDbImporter::PerformParallelTask, this,
auto method =async_?std::launch::async:std::launch::deferred;
res->push_back(std::async(method, &FolderToDbImporter::PerformParallelTask, this,
file_list, p->begin, p->begin + p->next_chunk_size));
p->begin = p->begin + p->next_chunk_size;
......@@ -185,9 +187,10 @@ void FolderToDbImporter::IgnoreDuplicates(bool ignore_duplicates) {
ignore_duplicates_ = ignore_duplicates;
}
unsigned int FolderToDbImporter::SetNParallelTasks(unsigned int ntasks) {
unsigned int FolderToDbImporter::SetNParallelTasks(unsigned int ntasks,bool async) {
unsigned int nthreads = std::thread::hardware_concurrency();
n_tasks_ = std::max((unsigned int)1, std::min(ntasks, nthreads));
async_ = async;
return n_tasks_;
}
......
......@@ -43,7 +43,7 @@ class FolderToDbImporter {
FolderToDbImportError Convert(const std::string& uri, const std::string& folder,
FolderImportStatistics* statistics = nullptr) const;
unsigned int SetNParallelTasks(unsigned int ntasks);
unsigned int SetNParallelTasks(unsigned int ntasks,bool async = true);
void IgnoreDuplicates(bool ignore_duplicates = true);
std::unique_ptr<hidra2::DatabaseFactory>
db_factory__; // modified in testings to mock system calls,otherwise do not touch
......@@ -51,6 +51,7 @@ class FolderToDbImporter {
private:
bool ignore_duplicates_{false};
unsigned int n_tasks_{1};
bool async_{true};
mutable std::string db_uri_ ;
mutable std::string db_collection_name;
FolderToDbImportError ConnectToDb(const std::unique_ptr<hidra2::Database>& db) const;
......
......@@ -238,7 +238,7 @@ TEST_F(FolderDBConverterTests, PassesFileListToInsertInParallel3by3) {
EXPECT_CALL(*(mock_dbf->db[2]), Insert(CompareFileInfo(file_infos[2]), _)).
WillOnce(testing::Return(DBError::kNoError));
converter.SetNParallelTasks(3);
converter.SetNParallelTasks(3,false);
auto error = converter.Convert(uri, folder);
ASSERT_THAT(error, Eq(FolderToDbImportError::kOK));
}
......@@ -252,7 +252,7 @@ TEST_F(FolderDBConverterTests, PassesFileListToInsertInParallel3by2) {
EXPECT_CALL(*(mock_dbf->db[1]), Insert(CompareFileInfo(file_infos[2]), _)).
WillOnce(testing::Return(DBError::kNoError));
converter.SetNParallelTasks(2);
converter.SetNParallelTasks(2,false);
auto error = converter.Convert(uri, folder);
ASSERT_THAT(error, Eq(FolderToDbImportError::kOK));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment