diff --git a/test/conftest.py b/test/conftest.py index 4ae49d8ca79980622e8190a552ede253eeb86478..5fce842686cea10f495fe73e4b13321b711b6963 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 9201e5fa44c6c2db75f6012ae195bff086764e83..1dc7e0a13ed8a42ba6b8e103e56852b8cb9327d5 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") )