提交 93a660fd 编写于 作者: P peng.xu

Merge branch 'branch-0.4.0' into 'branch-0.4.0'

MS-524 Add some unittest in event_test and resource_test

See merge request megasearch/milvus!516

Former-commit-id: c508a7c288b3ef55060a3d97046bf23d435c364b
......@@ -103,6 +103,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-518 - Add schedinst_test in scheduler
- MS-519 - Add event_test in scheduler
- MS-520 - Update resource_test in scheduler
- MS-524 - Add some unittest in event_test and resource_test
## New Feature
- MS-343 - Implement ResourceMgr
......
......@@ -32,10 +32,8 @@ public:
return type_;
}
inline virtual std::string
Dump() const {
return "<Event>";
}
virtual std::string
Dump() const = 0;
friend std::ostream &operator<<(std::ostream &out, const Event &event);
......
......@@ -19,27 +19,24 @@ TEST(EventTest, start_up_event) {
ResourceWPtr res(ResourcePtr(nullptr));
auto event = std::make_shared<StartUpEvent>(res);
ASSERT_FALSE(event->Dump().empty());
std::stringstream ss;
ss << event;
ASSERT_FALSE(ss.str().empty());
std::cout << *event;
std::cout << *EventPtr(event);
}
TEST(EventTest, load_completed_event) {
ResourceWPtr res(ResourcePtr(nullptr));
auto event = std::make_shared<LoadCompletedEvent>(res, nullptr);
ASSERT_FALSE(event->Dump().empty());
std::stringstream ss;
ss << event;
ASSERT_FALSE(ss.str().empty());
std::cout << *event;
std::cout << *EventPtr(event);
}
TEST(EventTest, finish_task_event) {
ResourceWPtr res(ResourcePtr(nullptr));
auto event = std::make_shared<FinishTaskEvent>(res, nullptr);
ASSERT_FALSE(event->Dump().empty());
std::stringstream ss;
ss << event;
ASSERT_FALSE(ss.str().empty());
std::cout << *event;
std::cout << *EventPtr(event);
}
......@@ -47,9 +44,8 @@ TEST(EventTest, tasktable_updated_event) {
ResourceWPtr res(ResourcePtr(nullptr));
auto event = std::make_shared<TaskTableUpdatedEvent>(res);
ASSERT_FALSE(event->Dump().empty());
std::stringstream ss;
ss << event;
ASSERT_FALSE(ss.str().empty());
std::cout << *event;
std::cout << *EventPtr(event);
}
}
......
......@@ -100,9 +100,11 @@ protected:
disk_resource_ = ResourceFactory::Create("ssd", "DISK", 0);
cpu_resource_ = ResourceFactory::Create("cpu", "CPU", 0);
gpu_resource_ = ResourceFactory::Create("gpu", "GPU", 0);
test_resource_ = std::make_shared<TestResource>("test", 0, true, true);
resources_.push_back(disk_resource_);
resources_.push_back(cpu_resource_);
resources_.push_back(gpu_resource_);
resources_.push_back(test_resource_);
auto subscriber = [&](EventPtr event) {
if (event->Type() == EventType::LOAD_COMPLETED) {
......@@ -125,10 +127,12 @@ protected:
disk_resource_->RegisterSubscriber(subscriber);
cpu_resource_->RegisterSubscriber(subscriber);
gpu_resource_->RegisterSubscriber(subscriber);
test_resource_->RegisterSubscriber(subscriber);
disk_resource_->Start();
cpu_resource_->Start();
gpu_resource_->Start();
test_resource_->Start();
}
void
......@@ -136,6 +140,7 @@ protected:
disk_resource_->Stop();
cpu_resource_->Stop();
gpu_resource_->Stop();
test_resource_->Stop();
}
void
......@@ -153,6 +158,7 @@ protected:
ResourcePtr disk_resource_;
ResourcePtr cpu_resource_;
ResourcePtr gpu_resource_;
ResourcePtr test_resource_;
std::vector<ResourcePtr> resources_;
uint64_t load_count_ = 0;
uint64_t exec_count_ = 0;
......@@ -236,6 +242,30 @@ TEST_F(ResourceAdvanceTest, gpu_resource_test) {
}
}
TEST_F(ResourceAdvanceTest, test_resource_test) {
const uint64_t NUM = 100;
std::vector<std::shared_ptr<TestTask>> tasks;
TableFileSchemaPtr dummy = nullptr;
for (uint64_t i = 0; i < NUM; ++i) {
auto task = std::make_shared<TestTask>(dummy);
tasks.push_back(task);
test_resource_->task_table().Put(task);
}
test_resource_->WakeupLoader();
WaitLoader(NUM);
for (uint64_t i = 0; i < NUM; ++i) {
ASSERT_EQ(tasks[i]->load_count_, 1);
}
test_resource_->WakeupExecutor();
WaitExecutor(NUM);
for (uint64_t i = 0; i < NUM; ++i) {
ASSERT_EQ(tasks[i]->exec_count_, 1);
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册