diff --git a/features/dcs_failsafe_mode.feature b/features/dcs_failsafe_mode.feature index 4a34b754..8345d8ea 100644 --- a/features/dcs_failsafe_mode.feature +++ b/features/dcs_failsafe_mode.feature @@ -4,8 +4,8 @@ Feature: dcs failsafe mode Scenario: check failsafe mode can be successfully enabled Given I start postgres0 And postgres0 is a leader after 10 seconds - And I sleep for 3 seconds - When I issue a PATCH request to http://127.0.0.1:8008/config with {"loop_wait": 2, "ttl": 20, "retry_timeout": 5, "failsafe_mode": true} + Then "config" key in DCS has ttl=30 after 10 seconds + When I issue a PATCH request to http://127.0.0.1:8008/config with {"loop_wait": 2, "ttl": 20, "retry_timeout": 3, "failsafe_mode": true} Then I receive a response code 200 And Response on GET http://127.0.0.1:8008/failsafe contains postgres0 after 10 seconds When I issue a GET request to http://127.0.0.1:8008/failsafe @@ -28,7 +28,6 @@ Feature: dcs failsafe mode When I do a backup of postgres0 And I shut down postgres0 When I start postgres1 in a cluster batman from backup with no_leader - And I sleep for 2 seconds Then postgres1 role is the replica after 12 seconds Scenario: check leader and replica are both in /failsafe key after leader is back @@ -59,12 +58,12 @@ Feature: dcs failsafe mode Given DCS is down And I kill postgres1 And I kill postmaster on postgres1 - And I sleep for 2 seconds Then postgres0 role is the replica after 12 seconds @dcs-failsafe Scenario: check known replica is promoted when leader is down and DCS is up - Given I shut down postgres0 + Given I kill postgres0 + And I shut down postmaster on postgres0 And DCS is up When I start postgres1 Then "members/postgres1" key in DCS has state=running after 10 seconds diff --git a/features/environment.py b/features/environment.py index e3c21252..79db5d16 100644 --- a/features/environment.py +++ b/features/environment.py @@ -162,9 +162,10 @@ class PatroniController(AbstractController): def stop(self, kill=False, timeout=15, postgres=False): if postgres: - return subprocess.call(['pg_ctl', '-D', self._data_dir, 'stop', '-mi', '-w']) + mode = 'i' if kill else 'f' + return subprocess.call(['pg_ctl', '-D', self._data_dir, 'stop', '-m' + mode, '-w']) super(PatroniController, self).stop(kill, timeout) - if isinstance(self._context.dcs_ctl, KubernetesController): + if isinstance(self._context.dcs_ctl, KubernetesController) and not kill: self._context.dcs_ctl.delete_pod(self._name[8:]) if self.watchdog: self.watchdog.stop() diff --git a/features/steps/basic_replication.py b/features/steps/basic_replication.py index 6718cb01..5977eb61 100644 --- a/features/steps/basic_replication.py +++ b/features/steps/basic_replication.py @@ -35,11 +35,16 @@ def kill_patroni(context, name): return context.pctl.stop(name, kill=True) -@step('I kill postmaster on {name:w}') +@step('I shut down postmaster on {name:w}') def stop_postgres(context, name): return context.pctl.stop(name, postgres=True) +@step('I kill postmaster on {name:w}') +def kill_postgres(context, name): + return context.pctl.stop(name, kill=True, postgres=True) + + @step('I add the table {table_name:w} to {pg_name:w}') def add_table(context, table_name, pg_name): # parse the configuration file and get the port diff --git a/features/steps/cascading_replication.py b/features/steps/cascading_replication.py index 9783fbae..c6b43f31 100644 --- a/features/steps/cascading_replication.py +++ b/features/steps/cascading_replication.py @@ -28,7 +28,7 @@ def check_member(context, name, key, value, time_limit): while time.time() < max_time: try: response = json.loads(context.dcs_ctl.query(name)) - dcs_value = response.get(key) + dcs_value = str(response.get(key)) if dcs_value == value: return except Exception: