-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
test_change_ip.py
96 lines (78 loc) · 2.64 KB
/
test_change_ip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pytest
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import assert_eq_with_retry
"""
Both ssl_conf.xml and no_ssl_conf.xml have the same port
"""
def _fill_nodes(nodes, shard):
for node in nodes:
node.query(
"""
CREATE DATABASE test;
CREATE TABLE test_table(date Date, id UInt32)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/test{shard}/replicated', '{replica}') PARTITION BY toYYYYMM(date) ORDER BY id;
""".format(
shard=shard, replica=node.name
)
)
cluster = ClickHouseCluster(__file__)
node1 = cluster.add_instance(
"node1",
main_configs=[
"configs/remote_servers.xml",
"configs/listen_host.xml",
"configs/ssl_conf.xml",
"configs/server.crt",
"configs/server.key",
"configs/dhparam.pem",
],
with_zookeeper=True,
ipv6_address="2001:3984:3989::1:1111",
)
node2 = cluster.add_instance(
"node2",
main_configs=[
"configs/remote_servers.xml",
"configs/listen_host.xml",
"configs/ssl_conf.xml",
"configs/server.crt",
"configs/server.key",
"configs/dhparam.pem",
],
with_zookeeper=True,
ipv6_address="2001:3984:3989::1:1112",
)
@pytest.fixture(scope="module")
def both_https_cluster():
try:
cluster.start()
_fill_nodes([node1, node2], 1)
yield cluster
finally:
cluster.shutdown()
def test_replication_when_node_ip_changed(both_https_cluster):
"""
Test for a bug when replication over HTTPS stops working when the IP of the source replica was changed.
node1 is a source node
node2 fethes data from node1
"""
node1.query("truncate table test_table")
node2.query("truncate table test_table")
# First we check, that normal replication works
node1.query(
"INSERT INTO test_table VALUES ('2022-10-01', 1), ('2022-10-02', 2), ('2022-10-03', 3)"
)
assert node1.query("SELECT count(*) from test_table") == "3\n"
assert_eq_with_retry(node2, "SELECT count(*) from test_table", "3")
# We change source node ip
cluster.restart_instance_with_ip_change(node1, "2001:3984:3989::1:7777")
# Put some data to source node1
node1.query(
"INSERT INTO test_table VALUES ('2018-10-01', 4), ('2018-10-02', 4), ('2018-10-03', 6)"
)
# Check that data is placed on node1
assert node1.query("SELECT count(*) from test_table") == "6\n"
# drop DNS cache
node2.query("SYSTEM DROP DNS CACHE")
# Data is fetched
assert_eq_with_retry(node2, "SELECT count(*) from test_table", "6")