From b9eb684c6feabf059db9a0bf15794096cf811176 Mon Sep 17 00:00:00 2001 From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com> Date: Thu, 13 Oct 2022 13:51:55 +0300 Subject: [PATCH] test: align Cluster.add_instance args types --- test/conftest.py | 35 ++++++++++++++++++++--------------- test/int/test_joining.py | 1 + 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 4ae49d8ca7..5fce842686 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -480,7 +480,7 @@ class Cluster: self, wait_ready=True, peers=None, - instance_id: str | bool | None = True, + instance_id: str | bool = True, failure_domain=dict(), init_replication_factor=1, ) -> Instance: @@ -489,30 +489,35 @@ class Cluster: `instance_id` specifies how the instance's id is generated in the following way: - - if `instance_id` is a string, it will be used as value for the - `--instance-id` command line option. - - If `instance_id` is `True` (default), this function will generate a - value for the `--instance-id` command line option. - - If `instance_id` is `False` or `None`, the instance will be started - without the `--instance-id` option, and the cluster will have to choose - the id. + + - if `instance_id` is a string, it will be used as a value for the + `--instance-id` command-line option. + + - If `instance_id` is `True` (default), the `--instance-id` command-line + option will be generated by the pytest according to the instances + sequence number in cluster. + + - If `instance_id` is `False`, the instance will be started + without the `--instance-id` command-line option and the particular value + will be generated by the cluster. """ i = 1 + len(self.instances) + generated_instance_id: str | None match instance_id: - case True: - instance_id = f"i{i}" - case False | None: - instance_id = None case str() as iid: - instance_id = iid + generated_instance_id = iid + case True: + generated_instance_id = f"i{i}" + case False: + generated_instance_id = None case _: raise Exception("unreachable") instance = Instance( binary_path=self.binary_path, cluster_id=self.id, - instance_id=instance_id, + instance_id=generated_instance_id, data_dir=f"{self.data_dir}/i{i}", host=self.base_host, port=self.base_port + i, @@ -534,7 +539,7 @@ class Cluster: def fail_to_add_instance( self, peers=None, - instance_id=None, + instance_id: str | bool = True, failure_domain=dict(), init_replication_factor=1, ): diff --git a/test/int/test_joining.py b/test/int/test_joining.py index 9201e5fa44..1dc7e0a13e 100644 --- a/test/int/test_joining.py +++ b/test/int/test_joining.py @@ -348,6 +348,7 @@ def test_fail_to_join(cluster: Cluster): # An instance with the given instance_id is already present in the cluster # so this instance cannot join # and therefore exits with failure + assert i1.instance_id is not None cluster.fail_to_add_instance( instance_id=i1.instance_id, failure_domain=dict(owner="Jim") ) -- GitLab