Skip to content
Snippets Groups Projects
Commit ebaa9ca2 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon: Committed by Georgy Moshkin
Browse files

test: dynamic discovery test

parent 87ce9b7b
No related branches found
No related tags found
1 merge request!82Feature/discovery/when raft initialized
Pipeline #4619 passed
...@@ -256,6 +256,9 @@ class Instance: ...@@ -256,6 +256,9 @@ class Instance:
def drop_db(self): def drop_db(self):
rmtree(self.data_dir) rmtree(self.data_dir)
def __hash__(self):
return hash(self.id) ^ hash(self.cluster_id) ^ hash(self.listen)
def __raft_status(self) -> RaftStatus: def __raft_status(self) -> RaftStatus:
status = self.call("picolib.raft_status") status = self.call("picolib.raft_status")
assert isinstance(status, dict) assert isinstance(status, dict)
...@@ -314,16 +317,7 @@ class Cluster: ...@@ -314,16 +317,7 @@ class Cluster:
assert not self.instances, "Already deployed" assert not self.instances, "Already deployed"
for i in range(1, instance_count + 1): for i in range(1, instance_count + 1):
instance = Instance( self.add_instance(i, wait_ready=False)
binary_path=self.binary_path,
instance_id=f"i{i}",
data_dir=f"{self.data_dir}/i{i}",
host=f"127.7.{self.subnet}.1",
port=3300 + i,
peers=[f"127.7.{self.subnet}.1:3301"],
)
self.instances.append(instance)
for instance in self.instances: for instance in self.instances:
instance.start() instance.start()
...@@ -334,6 +328,26 @@ class Cluster: ...@@ -334,6 +328,26 @@ class Cluster:
eprint(f" {self} deployed ".center(80, "=")) eprint(f" {self} deployed ".center(80, "="))
return self.instances return self.instances
def add_instance(self, i=None, wait_ready=True) -> Instance:
i = i or 1 + len(self.instances)
instance = Instance(
binary_path=self.binary_path,
instance_id=f"i{i}",
data_dir=f"{self.data_dir}/i{i}",
host=f"127.7.{self.subnet}.1",
port=3300 + i,
peers=[f"127.7.{self.subnet}.1:3301"],
)
self.instances.append(instance)
if wait_ready:
instance.start()
instance.wait_ready()
return instance
def kill_all(self): def kill_all(self):
for instance in self.instances: for instance in self.instances:
instance.kill() instance.kill()
......
...@@ -73,3 +73,18 @@ def test_request_follower(cluster2: Cluster): ...@@ -73,3 +73,18 @@ def test_request_follower(cluster2: Cluster):
with pytest.raises(TarantoolError) as e: with pytest.raises(TarantoolError) as e:
fake_join(i2, "fake-0", timeout=1) fake_join(i2, "fake-0", timeout=1)
assert e.value.args == ("ER_PROC_C", "not a leader") assert e.value.args == ("ER_PROC_C", "not a leader")
def test_discovery(cluster: Cluster):
cluster.deploy(instance_count=3)
i1, i2, i3 = cluster.instances
# make sure i1 is leader
i1.promote_or_fail()
# change leader
i2.promote_or_fail()
# add instance
i4 = cluster.add_instance()
i4.assert_raft_status("Follower", leader_id=i2.raft_id)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment