Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
6200ccb3
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,发现更多精彩内容 >>
提交
6200ccb3
编写于
5月 23, 2017
作者:
A
Alexey Zatelepin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improve waiting for instance startup in integration tests [#CLICKHOUSE-2821]
上级
c24f4c57
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
25 addition
and
9 deletion
+25
-9
dbms/tests/integration/helpers/cluster.py
dbms/tests/integration/helpers/cluster.py
+25
-9
未找到文件。
dbms/tests/integration/helpers/cluster.py
浏览文件 @
6200ccb3
...
...
@@ -39,6 +39,8 @@ class ClickHouseCluster:
self
.
base_cmd
=
[
'docker-compose'
,
'--project-directory'
,
self
.
base_dir
,
'--project-name'
,
self
.
project_name
]
self
.
instances
=
{}
self
.
with_zookeeper
=
False
self
.
docker_client
=
None
self
.
is_up
=
False
...
...
@@ -51,10 +53,10 @@ class ClickHouseCluster:
"""
if
self
.
is_up
:
raise
Exception
(
'Can
\'
t add instance %s: cluster is already up!'
%
name
)
raise
Exception
(
"Can
\'
t add instance %s: cluster is already up!"
%
name
)
if
name
in
self
.
instances
:
raise
Exception
(
'Can
\'
t add instance %s: there is already an instance with the same name!'
%
name
)
raise
Exception
(
"Can
\'
t add instance `%s': there is already an instance with the same name!"
%
name
)
instance
=
ClickHouseInstance
(
self
.
base_dir
,
name
,
custom_configs
,
with_zookeeper
,
self
.
base_configs_dir
,
self
.
server_bin_path
)
self
.
instances
[
name
]
=
instance
...
...
@@ -75,15 +77,19 @@ class ClickHouseCluster:
subprocess
.
check_call
(
self
.
base_cmd
+
[
'up'
,
'-d'
])
docker_client
=
docker
.
from_env
()
self
.
docker_client
=
docker
.
from_env
()
start_deadline
=
time
.
time
()
+
10.0
# seconds
for
instance
in
self
.
instances
.
values
():
instance
.
docker_client
=
self
.
docker_client
# According to how docker-compose names containers.
instance
.
docker_id
=
self
.
project_name
+
'_'
+
instance
.
name
+
'_1'
container
=
docker_client
.
containers
.
get
(
instance
.
docker_id
)
container
=
self
.
docker_client
.
containers
.
get
(
instance
.
docker_id
)
instance
.
ip_address
=
container
.
attrs
[
'NetworkSettings'
][
'Networks'
].
values
()[
0
][
'IPAddress'
]
instance
.
wait_for_start
()
instance
.
wait_for_start
(
start_deadline
)
instance
.
client
=
Client
(
instance
.
ip_address
,
command
=
self
.
client_bin_path
)
...
...
@@ -96,7 +102,10 @@ class ClickHouseCluster:
subprocess
.
check_call
(
self
.
base_cmd
+
[
'down'
,
'--volumes'
])
self
.
is_up
=
False
self
.
docker_client
=
None
for
instance
in
self
.
instances
.
values
():
instance
.
docker_client
=
None
instance
.
docker_id
=
None
instance
.
ip_address
=
None
instance
.
client
=
None
...
...
@@ -143,6 +152,7 @@ class ClickHouseInstance:
self
.
path
=
p
.
abspath
(
p
.
join
(
base_path
,
name
))
self
.
docker_compose_path
=
p
.
join
(
self
.
path
,
'docker_compose.yml'
)
self
.
docker_client
=
None
self
.
docker_id
=
None
self
.
ip_address
=
None
self
.
client
=
None
...
...
@@ -152,18 +162,24 @@ class ClickHouseInstance:
return
self
.
client
.
query
(
sql
,
stdin
)
def
wait_for_start
(
self
,
timeout
=
10.0
):
deadline
=
time
.
time
()
+
timeout
def
wait_for_start
(
self
,
deadline
):
while
True
:
if
time
.
time
()
>=
deadline
:
raise
Exception
(
"Timed out while waiting for instance {} with ip address {} to start"
.
format
(
self
.
name
,
self
.
ip_address
))
if
self
.
docker_client
.
containers
.
get
(
self
.
docker_id
).
status
==
'exited'
:
raise
Exception
(
"Instance `{}' failed to start"
.
format
(
self
.
name
))
time_left
=
deadline
-
time
.
time
()
if
time_left
<=
0
:
raise
Exception
(
"Timed out while waiting for instance `{}' with ip address {} to start"
.
format
(
self
.
name
,
self
.
ip_address
))
# Repeatedly poll the instance address until there is something that listens there.
# Usually it means that ClickHouse is ready to accept queries.
try
:
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
settimeout
(
time_left
)
sock
.
connect
((
self
.
ip_address
,
9000
))
return
except
socket
.
timeout
:
continue
except
socket
.
error
as
e
:
if
e
.
errno
==
errno
.
ECONNREFUSED
:
time
.
sleep
(
0.1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录