From 2af41317e6431fb888d3b74fa632a60b8a987c7b Mon Sep 17 00:00:00 2001 From: wxyu Date: Mon, 9 Sep 2019 19:13:30 +0800 Subject: [PATCH] MS-530 Add unittest for SearchTask->Load Former-commit-id: dff97021943c200ca003d766af221c008e5f0ac2 --- cpp/CHANGELOG.md | 1 + cpp/src/scheduler/task/SearchTask.cpp | 38 ++++++++++++-------------- cpp/unittest/scheduler/normal_test.cpp | 2 +- cpp/unittest/scheduler/task_test.cpp | 25 +++++++++++++++-- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index dab772d0..96745a8c 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -107,6 +107,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-525 - Disable parallel reduce in SearchTask - MS-527 - Update scheduler_test and enable it - MS-528 - Hide some config used future +- MS-530 - Add unittest for SearchTask->Load ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/task/SearchTask.cpp b/cpp/src/scheduler/task/SearchTask.cpp index 47d55329..8d760750 100644 --- a/cpp/src/scheduler/task/SearchTask.cpp +++ b/cpp/src/scheduler/task/SearchTask.cpp @@ -96,33 +96,31 @@ XSearchTask::XSearchTask(TableFileSchemaPtr file) void XSearchTask::Load(LoadType type, uint8_t device_id) { server::TimeRecorder rc(""); + Status stat = Status::OK(); + std::string error_msg; try { if (type == LoadType::DISK2CPU) { - auto stat = index_engine_->Load(); - if(!stat.ok()) { - //typical error: file not available - ENGINE_LOG_ERROR << "Failed to load index file: file not available"; - - for(auto& context : search_contexts_) { - context->IndexSearchDone(file_->id_);//mark as done avoid dead lock, even failed - } - - return; - } + stat = index_engine_->Load(); } else if (type == LoadType::CPU2GPU) { - index_engine_->CopyToGpu(device_id); + stat = index_engine_->CopyToGpu(device_id); } else if (type == LoadType::GPU2CPU) { - index_engine_->CopyToCpu(); + stat = index_engine_->CopyToCpu(); } else { - // TODO: exception - std::string msg = "Wrong load type"; - ENGINE_LOG_ERROR << msg; + error_msg = "Wrong load type"; + stat = Status(SERVER_UNEXPECTED_ERROR, error_msg); } } catch (std::exception &ex) { //typical error: out of disk space or permition denied - std::string msg = "Failed to load index file: " + std::string(ex.what()); - ENGINE_LOG_ERROR << msg; + error_msg = "Failed to load index file: " + std::string(ex.what()); + stat = Status(SERVER_UNEXPECTED_ERROR, error_msg); + } + + if (!stat.ok()) { + if (error_msg.empty()) + error_msg = std::string("Failed to load index file: file not available"); + //typical error: file not available + ENGINE_LOG_ERROR << error_msg; for (auto &context : search_contexts_) { context->IndexSearchDone(file_->id_);//mark as done avoid dead lock, even failed @@ -241,7 +239,7 @@ Status XSearchTask::ClusterResult(const std::vector &output_ids, // if (NeedParallelReduce(nq, topk)) { // ParallelReduce(reduce_worker, nq); // } else { - reduce_worker(0, nq); + reduce_worker(0, nq); // } return Status::OK(); @@ -346,7 +344,7 @@ Status XSearchTask::TopkResult(SearchContext::ResultSet &result_src, // if (NeedParallelReduce(result_src.size(), topk)) { // ParallelReduce(ReduceWorker, result_src.size()); // } else { - ReduceWorker(0, result_src.size()); + ReduceWorker(0, result_src.size()); // } return Status::OK(); diff --git a/cpp/unittest/scheduler/normal_test.cpp b/cpp/unittest/scheduler/normal_test.cpp index bb438ab9..c679a356 100644 --- a/cpp/unittest/scheduler/normal_test.cpp +++ b/cpp/unittest/scheduler/normal_test.cpp @@ -11,7 +11,7 @@ using namespace zilliz::milvus::engine; -TEST(normal_test, DISABLED_inst_test) { +TEST(normal_test, inst_test) { // ResourceMgr only compose resources, provide unified event auto res_mgr = ResMgrInst::GetInstance(); diff --git a/cpp/unittest/scheduler/task_test.cpp b/cpp/unittest/scheduler/task_test.cpp index b3c29af3..f42006fc 100644 --- a/cpp/unittest/scheduler/task_test.cpp +++ b/cpp/unittest/scheduler/task_test.cpp @@ -1,4 +1,23 @@ -// -// Created by wxyu on 19-9-9. -// +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#include "scheduler/task/SearchTask.h" +#include + + +namespace zilliz { +namespace milvus { +namespace engine { + + +TEST(TaskTest, invalid_index) { + auto search_task = std::make_shared(nullptr); + search_task->Load(LoadType::TEST, 10); +} + +} +} +} -- GitLab