mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Speed up dcs failsafe behave tests (#2890)
- get rid from sleeps - reduce retry_timeout - avoid graceful Patroni shut down while DCS is "paused", just kill Patroni and after that gracefully stop postgres - don't try to delete Pod when Patroni is killed. If K8s API is paused it takes ages The run time on my laptop is reduced from 2m to 1m28s.
This commit is contained in:
@@ -4,8 +4,8 @@ Feature: dcs failsafe mode
|
|||||||
Scenario: check failsafe mode can be successfully enabled
|
Scenario: check failsafe mode can be successfully enabled
|
||||||
Given I start postgres0
|
Given I start postgres0
|
||||||
And postgres0 is a leader after 10 seconds
|
And postgres0 is a leader after 10 seconds
|
||||||
And I sleep for 3 seconds
|
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": 5, "failsafe_mode": true}
|
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
|
Then I receive a response code 200
|
||||||
And Response on GET http://127.0.0.1:8008/failsafe contains postgres0 after 10 seconds
|
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
|
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
|
When I do a backup of postgres0
|
||||||
And I shut down postgres0
|
And I shut down postgres0
|
||||||
When I start postgres1 in a cluster batman from backup with no_leader
|
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
|
Then postgres1 role is the replica after 12 seconds
|
||||||
|
|
||||||
Scenario: check leader and replica are both in /failsafe key after leader is back
|
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
|
Given DCS is down
|
||||||
And I kill postgres1
|
And I kill postgres1
|
||||||
And I kill postmaster on postgres1
|
And I kill postmaster on postgres1
|
||||||
And I sleep for 2 seconds
|
|
||||||
Then postgres0 role is the replica after 12 seconds
|
Then postgres0 role is the replica after 12 seconds
|
||||||
|
|
||||||
@dcs-failsafe
|
@dcs-failsafe
|
||||||
Scenario: check known replica is promoted when leader is down and DCS is up
|
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
|
And DCS is up
|
||||||
When I start postgres1
|
When I start postgres1
|
||||||
Then "members/postgres1" key in DCS has state=running after 10 seconds
|
Then "members/postgres1" key in DCS has state=running after 10 seconds
|
||||||
|
|||||||
@@ -162,9 +162,10 @@ class PatroniController(AbstractController):
|
|||||||
|
|
||||||
def stop(self, kill=False, timeout=15, postgres=False):
|
def stop(self, kill=False, timeout=15, postgres=False):
|
||||||
if postgres:
|
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)
|
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:])
|
self._context.dcs_ctl.delete_pod(self._name[8:])
|
||||||
if self.watchdog:
|
if self.watchdog:
|
||||||
self.watchdog.stop()
|
self.watchdog.stop()
|
||||||
|
|||||||
@@ -35,11 +35,16 @@ def kill_patroni(context, name):
|
|||||||
return context.pctl.stop(name, kill=True)
|
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):
|
def stop_postgres(context, name):
|
||||||
return context.pctl.stop(name, postgres=True)
|
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}')
|
@step('I add the table {table_name:w} to {pg_name:w}')
|
||||||
def add_table(context, table_name, pg_name):
|
def add_table(context, table_name, pg_name):
|
||||||
# parse the configuration file and get the port
|
# parse the configuration file and get the port
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def check_member(context, name, key, value, time_limit):
|
|||||||
while time.time() < max_time:
|
while time.time() < max_time:
|
||||||
try:
|
try:
|
||||||
response = json.loads(context.dcs_ctl.query(name))
|
response = json.loads(context.dcs_ctl.query(name))
|
||||||
dcs_value = response.get(key)
|
dcs_value = str(response.get(key))
|
||||||
if dcs_value == value:
|
if dcs_value == value:
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user