mirror of
https://github.com/sogou/workflow.git
synced 2026-10-17 04:31:07 +08:00
Update unit tests (#104)
* test: correct TestSuitName and TestName * test: add graph_unittest.cc Add unittests of WFGraphTask.
This commit is contained in:
@@ -35,6 +35,7 @@ set(TEST_LIST
|
||||
redis_unittest
|
||||
mysql_unittest
|
||||
facilities_unittest
|
||||
graph_unittest
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
|
||||
@@ -35,7 +35,7 @@ static void __arr_check(int *arr, int n)
|
||||
EXPECT_LE(arr[i - 1], arr[i]);
|
||||
}
|
||||
|
||||
TEST(sort, algo_unittest)
|
||||
TEST(algo_unittest, sort)
|
||||
{
|
||||
static constexpr int n = 100000;
|
||||
int *arr = new int[n];
|
||||
@@ -65,7 +65,7 @@ TEST(sort, algo_unittest)
|
||||
delete []arr;
|
||||
}
|
||||
|
||||
TEST(parallel_sort, algo_unittest)
|
||||
TEST(algo_unittest, parallel_sort)
|
||||
{
|
||||
static constexpr int n = 100000;
|
||||
int *arr = new int[n];
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#define GET_CURRENT_MICRO std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()
|
||||
|
||||
TEST(usleep, facilities_unittest)
|
||||
TEST(facilities_unittest, usleep)
|
||||
{
|
||||
int64_t st = GET_CURRENT_MICRO;
|
||||
WFFacilities::usleep(1000000);
|
||||
@@ -34,7 +34,7 @@ TEST(usleep, facilities_unittest)
|
||||
EXPECT_LE(ed - st, 10000000) << "usleep too slow";
|
||||
}
|
||||
|
||||
TEST(async_usleep, facilities_unittest)
|
||||
TEST(facilities_unittest, async_usleep)
|
||||
{
|
||||
int64_t st = GET_CURRENT_MICRO;
|
||||
WFFacilities::async_usleep(1000000).wait();
|
||||
@@ -42,7 +42,7 @@ TEST(async_usleep, facilities_unittest)
|
||||
EXPECT_LE(ed - st, 10000000) << "async_usleep too slow";
|
||||
}
|
||||
|
||||
TEST(request, facilities_unittest)
|
||||
TEST(facilities_unittest, request)
|
||||
{
|
||||
protocol::HttpRequest req;
|
||||
req.set_method(HttpMethodGet);
|
||||
@@ -62,7 +62,7 @@ TEST(request, facilities_unittest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(async_request, facilities_unittest)
|
||||
TEST(facilities_unittest, async_request)
|
||||
{
|
||||
protocol::HttpRequest req;
|
||||
req.set_method(HttpMethodGet);
|
||||
@@ -78,7 +78,7 @@ TEST(async_request, facilities_unittest)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(fileIO, facilities_unittest)
|
||||
TEST(facilities_unittest, fileIO)
|
||||
{
|
||||
uint64_t data = 0x1234;
|
||||
ssize_t sz;
|
||||
@@ -98,7 +98,7 @@ static inline void f(int i, WFFacilities::WaitGroup *wg)
|
||||
wg->done();
|
||||
}
|
||||
|
||||
TEST(WaitGroup, facilities_unittest)
|
||||
TEST(facilities_unittest, WaitGroup)
|
||||
{
|
||||
WFFacilities::WaitGroup wg(100);
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright (c) 2020 Sogou, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Author: Liu Yang (liuyang216492@sogou-inc.com)
|
||||
*/
|
||||
|
||||
#include <atomic>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "workflow/WFTaskFactory.h"
|
||||
#include "workflow/WFFacilities.h"
|
||||
|
||||
static SubTask *create_task(int& target)
|
||||
{
|
||||
static std::atomic<int> generator;
|
||||
return WFTaskFactory::create_timer_task(0, [&](WFTimerTask *)
|
||||
{
|
||||
target = generator++;
|
||||
});
|
||||
}
|
||||
|
||||
TEST(graph_unittest, WFGraphTask1)
|
||||
{
|
||||
WFFacilities::WaitGroup wait_group(1);
|
||||
|
||||
auto graph = WFTaskFactory::create_graph_task([&wait_group](WFGraphTask *){ wait_group.done(); });
|
||||
|
||||
int ta, tb, tc, td;
|
||||
|
||||
auto& a = graph->create_graph_node(create_task(ta));
|
||||
auto& b = graph->create_graph_node(create_task(tb));
|
||||
auto& c = graph->create_graph_node(create_task(tc));
|
||||
auto& d = graph->create_graph_node(create_task(td));
|
||||
|
||||
a --> b <-- c --> d --> a;
|
||||
c --> a;
|
||||
|
||||
graph->start();
|
||||
wait_group.wait();
|
||||
|
||||
EXPECT_LT(ta, tb);
|
||||
EXPECT_LT(tc, tb);
|
||||
EXPECT_LT(tc, td);
|
||||
EXPECT_LT(td, ta);
|
||||
EXPECT_LT(tc, ta);
|
||||
}
|
||||
|
||||
TEST(graph_unittest, WFGraphTask2)
|
||||
{
|
||||
WFFacilities::WaitGroup wait_group(1);
|
||||
|
||||
auto graph = WFTaskFactory::create_graph_task([&wait_group](WFGraphTask *){ wait_group.done(); });
|
||||
|
||||
constexpr int N = 4096 - 1;
|
||||
|
||||
auto target = new int[N];
|
||||
auto node = new WFGraphNode *[N];
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
node[i] = &graph->create_graph_node(create_task(target[i]));
|
||||
|
||||
for (int i = 1; i < N; i++)
|
||||
node[i]->precede(*node[(i - 1) / 2]);
|
||||
|
||||
graph->start();
|
||||
wait_group.wait();
|
||||
|
||||
for (int i = 1; i < N; i++)
|
||||
EXPECT_LT(target[i], target[(i - 1) / 2]);
|
||||
|
||||
delete[] target;
|
||||
delete[] node;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ static void __http_process(WFHttpTask *task)
|
||||
resp->add_header_pair("Content-Type", "text/plain");
|
||||
}
|
||||
|
||||
TEST(WFHttpTask1, http_unittest)
|
||||
TEST(http_unittest, WFHttpTask1)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -69,7 +69,7 @@ TEST(WFHttpTask1, http_unittest)
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
TEST(WFHttpTask2, http_unittest)
|
||||
TEST(http_unittest, WFHttpTask2)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -98,7 +98,7 @@ TEST(WFHttpTask2, http_unittest)
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
TEST(WFHttpTask3, http_unittest)
|
||||
TEST(http_unittest, WFHttpTask3)
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen("server.crt", "w");
|
||||
|
||||
@@ -48,7 +48,7 @@ static void test_client(const char *url, const char *sql, std::mutex& mutex, std
|
||||
task->start();
|
||||
}
|
||||
|
||||
TEST(WFMySQLTask1, mysql_unittest)
|
||||
TEST(mysql_unittest, WFMySQLTask1)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
|
||||
@@ -136,7 +136,7 @@ static void test_client(const char *url, std::mutex& mutex, std::condition_varia
|
||||
flow.start();
|
||||
}
|
||||
|
||||
TEST(WFRedisTask1, redis_unittest)
|
||||
TEST(redis_unittest, WFRedisTask1)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -153,7 +153,7 @@ TEST(WFRedisTask1, redis_unittest)
|
||||
server.stop();
|
||||
}
|
||||
|
||||
TEST(WFRedisTask2, redis_unittest)
|
||||
TEST(redis_unittest, WFRedisTask2)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#define GET_CURRENT_MICRO std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()
|
||||
|
||||
TEST(WFTimerTask, task_unittest)
|
||||
TEST(task_unittest, WFTimerTask)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -56,7 +56,7 @@ TEST(WFTimerTask, task_unittest)
|
||||
EXPECT_LE(ed - st, 10000000) << "Timer Task too slow";
|
||||
}
|
||||
|
||||
TEST(WFCounterTask1, task_unittest)
|
||||
TEST(task_unittest, WFCounterTask1)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -92,7 +92,7 @@ TEST(WFCounterTask1, task_unittest)
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
TEST(WFCounterTask2, task_unittest)
|
||||
TEST(task_unittest, WFCounterTask2)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -125,7 +125,7 @@ TEST(WFCounterTask2, task_unittest)
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
TEST(WFGoTask, task_unittest)
|
||||
TEST(task_unittest, WFGoTask)
|
||||
{
|
||||
srand(time(NULL));
|
||||
std::mutex mutex;
|
||||
@@ -155,7 +155,7 @@ TEST(WFGoTask, task_unittest)
|
||||
EXPECT_EQ(edit_inner, 100);
|
||||
}
|
||||
|
||||
TEST(WFThreadTask, task_unittest)
|
||||
TEST(task_unittest, WFThreadTask)
|
||||
{
|
||||
std::mutex mutex;
|
||||
std::condition_variable cond;
|
||||
@@ -195,7 +195,7 @@ TEST(WFThreadTask, task_unittest)
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
TEST(WFFileIOTask, task_unittest)
|
||||
TEST(task_unittest, WFFileIOTask)
|
||||
{
|
||||
srand(time(NULL));
|
||||
std::mutex mutex;
|
||||
|
||||
Reference in New Issue
Block a user