Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
f25b96be
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f25b96be
编写于
6月 30, 2019
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved a few tests to gtest
上级
b76d5a7c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
160 addition
and
22 deletion
+160
-22
dbms/src/Common/tests/CMakeLists.txt
dbms/src/Common/tests/CMakeLists.txt
+0
-15
dbms/src/Common/tests/gtest_shell_command.cpp
dbms/src/Common/tests/gtest_shell_command.cpp
+72
-0
dbms/src/Common/tests/gtest_thread_pool_concurrent_wait.cpp
dbms/src/Common/tests/gtest_thread_pool_concurrent_wait.cpp
+8
-3
dbms/src/Common/tests/gtest_thread_pool_limit.cpp
dbms/src/Common/tests/gtest_thread_pool_limit.cpp
+32
-0
dbms/src/Common/tests/gtest_thread_pool_loop.cpp
dbms/src/Common/tests/gtest_thread_pool_loop.cpp
+10
-4
dbms/src/Common/tests/gtest_thread_pool_schedule_exception.cpp
...src/Common/tests/gtest_thread_pool_schedule_exception.cpp
+38
-0
未找到文件。
dbms/src/Common/tests/CMakeLists.txt
浏览文件 @
f25b96be
...
@@ -41,9 +41,6 @@ target_link_libraries (compact_array PRIVATE clickhouse_common_io ${Boost_FILESY
...
@@ -41,9 +41,6 @@ target_link_libraries (compact_array PRIVATE clickhouse_common_io ${Boost_FILESY
add_executable
(
radix_sort radix_sort.cpp
)
add_executable
(
radix_sort radix_sort.cpp
)
target_link_libraries
(
radix_sort PRIVATE clickhouse_common_io
)
target_link_libraries
(
radix_sort PRIVATE clickhouse_common_io
)
add_executable
(
shell_command_test shell_command_test.cpp
)
target_link_libraries
(
shell_command_test PRIVATE clickhouse_common_io
)
add_executable
(
arena_with_free_lists arena_with_free_lists.cpp
)
add_executable
(
arena_with_free_lists arena_with_free_lists.cpp
)
target_link_libraries
(
arena_with_free_lists PRIVATE clickhouse_compression clickhouse_common_io
)
target_link_libraries
(
arena_with_free_lists PRIVATE clickhouse_compression clickhouse_common_io
)
...
@@ -53,18 +50,6 @@ target_link_libraries (pod_array PRIVATE clickhouse_common_io)
...
@@ -53,18 +50,6 @@ target_link_libraries (pod_array PRIVATE clickhouse_common_io)
add_executable
(
thread_creation_latency thread_creation_latency.cpp
)
add_executable
(
thread_creation_latency thread_creation_latency.cpp
)
target_link_libraries
(
thread_creation_latency PRIVATE clickhouse_common_io
)
target_link_libraries
(
thread_creation_latency PRIVATE clickhouse_common_io
)
add_executable
(
thread_pool thread_pool.cpp
)
target_link_libraries
(
thread_pool PRIVATE clickhouse_common_io
)
add_executable
(
thread_pool_2 thread_pool_2.cpp
)
target_link_libraries
(
thread_pool_2 PRIVATE clickhouse_common_io
)
add_executable
(
thread_pool_3 thread_pool_3.cpp
)
target_link_libraries
(
thread_pool_3 PRIVATE clickhouse_common_io
)
add_executable
(
thread_pool_schedule_exception thread_pool_schedule_exception.cpp
)
target_link_libraries
(
thread_pool_schedule_exception PRIVATE clickhouse_common_io
)
add_executable
(
multi_version multi_version.cpp
)
add_executable
(
multi_version multi_version.cpp
)
target_link_libraries
(
multi_version PRIVATE clickhouse_common_io
)
target_link_libraries
(
multi_version PRIVATE clickhouse_common_io
)
add_check
(
multi_version
)
add_check
(
multi_version
)
...
...
dbms/src/Common/tests/
shell_command_test
.cpp
→
dbms/src/Common/tests/
gtest_shell_command
.cpp
浏览文件 @
f25b96be
...
@@ -4,48 +4,62 @@
...
@@ -4,48 +4,62 @@
#include <IO/copyData.h>
#include <IO/copyData.h>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <IO/ReadBufferFromString.h>
#include <IO/ReadBufferFromString.h>
#include <IO/ReadHelpers.h>
#include <chrono>
#include <chrono>
#include <thread>
#include <thread>
#pragma GCC diagnostic ignored "-Wsign-compare"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wundef"
#endif
#include <gtest/gtest.h>
using
namespace
DB
;
using
namespace
DB
;
int
main
(
int
,
char
**
)
TEST
(
ShellCommand
,
Execute
)
try
{
{
{
auto
command
=
ShellCommand
::
execute
(
"echo 'Hello, world!'"
);
auto
command
=
ShellCommand
::
execute
(
"echo 'Hello, world!'"
);
WriteBufferFromFileDescriptor
out
(
STDOUT_FILENO
);
std
::
string
res
;
copyData
(
command
->
out
,
out
);
readStringUntilEOF
(
res
,
command
->
out
);
command
->
wait
();
command
->
wait
(
);
EXPECT_EQ
(
res
,
"Hello, world!
\n
"
);
}
}
{
TEST
(
ShellCommand
,
ExecuteDirect
)
auto
command
=
ShellCommand
::
executeDirect
(
"/bin/echo"
,
{
"Hello, world!"
});
{
auto
command
=
ShellCommand
::
executeDirect
(
"/bin/echo"
,
{
"Hello, world!"
});
WriteBufferFromFileDescriptor
out
(
STDOUT_FILENO
);
std
::
string
res
;
copyData
(
command
->
out
,
out
);
readStringUntilEOF
(
res
,
command
->
out
);
command
->
wait
();
command
->
wait
(
);
EXPECT_EQ
(
res
,
"Hello, world!
\n
"
);
}
}
{
TEST
(
ShellCommand
,
ExecuteWithInput
)
auto
command
=
ShellCommand
::
execute
(
"cat"
);
{
auto
command
=
ShellCommand
::
execute
(
"cat"
);
String
in_str
=
"Hello, world!
\n
"
;
String
in_str
=
"Hello, world!
\n
"
;
ReadBufferFromString
in
(
in_str
);
ReadBufferFromString
in
(
in_str
);
copyData
(
in
,
command
->
in
);
copyData
(
in
,
command
->
in
);
command
->
in
.
close
();
command
->
in
.
close
();
WriteBufferFromFileDescriptor
out
(
STDOUT_FILENO
);
std
::
string
res
;
copyData
(
command
->
out
,
out
);
readStringUntilEOF
(
res
,
command
->
out
);
command
->
wait
();
command
->
wait
(
);
EXPECT_EQ
(
res
,
"Hello, world!
\n
"
);
}
}
TEST
(
ShellCommand
,
AutoWait
)
{
// <defunct> hunting:
// <defunct> hunting:
for
(
int
i
=
0
;
i
<
1000
;
++
i
)
for
(
int
i
=
0
;
i
<
1000
;
++
i
)
{
{
...
@@ -56,8 +70,3 @@ try
...
@@ -56,8 +70,3 @@ try
// std::cerr << "inspect me: ps auxwwf" << "\n";
// std::cerr << "inspect me: ps auxwwf" << "\n";
// std::this_thread::sleep_for(std::chrono::seconds(100));
// std::this_thread::sleep_for(std::chrono::seconds(100));
}
}
catch
(...)
{
std
::
cerr
<<
getCurrentExceptionMessage
(
false
)
<<
"
\n
"
;
return
1
;
}
dbms/src/Common/tests/
thread_pool
.cpp
→
dbms/src/Common/tests/
gtest_thread_pool_concurrent_wait
.cpp
浏览文件 @
f25b96be
#include <Common/ThreadPool.h>
#include <Common/ThreadPool.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wundef"
#endif
#include <gtest/gtest.h>
/** Reproduces bug in ThreadPool.
/** Reproduces bug in ThreadPool.
* It get stuck if we call 'wait' many times from many other threads simultaneously.
* It get stuck if we call 'wait' many times from many other threads simultaneously.
*/
*/
int
main
(
int
,
char
**
)
TEST
(
ThreadPool
,
ConcurrentWait
)
{
{
auto
worker
=
[]
auto
worker
=
[]
{
{
...
@@ -29,6 +36,4 @@ int main(int, char **)
...
@@ -29,6 +36,4 @@ int main(int, char **)
waiting_pool
.
schedule
([
&
pool
]{
pool
.
wait
();
});
waiting_pool
.
schedule
([
&
pool
]{
pool
.
wait
();
});
waiting_pool
.
wait
();
waiting_pool
.
wait
();
return
0
;
}
}
dbms/src/Common/tests/
thread_pool_3
.cpp
→
dbms/src/Common/tests/
gtest_thread_pool_limit
.cpp
浏览文件 @
f25b96be
#include <
mutex
>
#include <
atomic
>
#include <iostream>
#include <iostream>
#include <Common/ThreadPool.h>
#include <Common/ThreadPool.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wundef"
#endif
#include <gtest/gtest.h>
/// Test for thread self-removal when number of free threads in pool is too large.
/// Test for thread self-removal when number of free threads in pool is too large.
/// Just checks that nothing weird happens.
/// Just checks that nothing weird happens.
template
<
typename
Pool
>
template
<
typename
Pool
>
void
test
()
int
test
()
{
{
Pool
pool
(
10
,
2
,
10
);
Pool
pool
(
10
,
2
,
10
);
std
::
mutex
mutex
;
std
::
atomic
<
int
>
counter
{
0
}
;
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
pool
.
schedule
([
&
]{
std
::
lock_guard
lock
(
mutex
);
std
::
cerr
<<
'.'
;
});
pool
.
schedule
([
&
]{
++
counter
;
});
pool
.
wait
();
pool
.
wait
();
return
counter
;
}
}
int
main
(
int
,
char
**
)
TEST
(
ThreadPool
,
ThreadRemoval
)
{
{
test
<
FreeThreadPool
>
();
EXPECT_EQ
(
test
<
FreeThreadPool
>
(),
10
);
std
::
cerr
<<
'\n'
;
EXPECT_EQ
(
test
<
ThreadPool
>
(),
10
);
test
<
ThreadPool
>
();
std
::
cerr
<<
'\n'
;
return
0
;
}
}
dbms/src/Common/tests/
thread_pool_2
.cpp
→
dbms/src/Common/tests/
gtest_thread_pool_loop
.cpp
浏览文件 @
f25b96be
...
@@ -2,10 +2,17 @@
...
@@ -2,10 +2,17 @@
#include <iostream>
#include <iostream>
#include <Common/ThreadPool.h>
#include <Common/ThreadPool.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wundef"
#endif
#include <gtest/gtest.h>
int
main
(
int
,
char
**
)
TEST
(
ThreadPool
,
Loop
)
{
{
std
::
atomic
<
size_
t
>
res
{
0
};
std
::
atomic
<
in
t
>
res
{
0
};
for
(
size_t
i
=
0
;
i
<
1000
;
++
i
)
for
(
size_t
i
=
0
;
i
<
1000
;
++
i
)
{
{
...
@@ -16,6 +23,5 @@ int main(int, char **)
...
@@ -16,6 +23,5 @@ int main(int, char **)
pool
.
wait
();
pool
.
wait
();
}
}
std
::
cerr
<<
res
<<
"
\n
"
;
EXPECT_EQ
(
res
,
16000
);
return
0
;
}
}
dbms/src/Common/tests/thread_pool_schedule_exception.cpp
→
dbms/src/Common/tests/
gtest_
thread_pool_schedule_exception.cpp
浏览文件 @
f25b96be
...
@@ -2,8 +2,15 @@
...
@@ -2,8 +2,15 @@
#include <stdexcept>
#include <stdexcept>
#include <Common/ThreadPool.h>
#include <Common/ThreadPool.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#pragma clang diagnostic ignored "-Wundef"
#endif
#include <gtest/gtest.h>
int
main
(
int
,
char
**
)
bool
check
()
{
{
ThreadPool
pool
(
10
);
ThreadPool
pool
(
10
);
...
@@ -11,15 +18,21 @@ int main(int, char **)
...
@@ -11,15 +18,21 @@ int main(int, char **)
try
try
{
{
while
(
true
)
for
(
size_t
i
=
0
;
i
<
100
;
++
i
)
pool
.
schedule
([]{});
/// An exception will be rethrown from this method.
pool
.
schedule
([]{});
/// An exception will be rethrown from this method.
}
}
catch
(
const
std
::
runtime_error
&
e
)
catch
(
const
std
::
runtime_error
&
)
{
{
std
::
cerr
<<
e
.
what
()
<<
"
\n
"
;
return
true
;
}
}
pool
.
wait
();
pool
.
wait
();
return
0
;
return
false
;
}
TEST
(
ThreadPool
,
ExceptionFromSchedule
)
{
EXPECT_TRUE
(
check
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录