Skip to content

Commit

Permalink
More review items (will squash)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedodd committed Oct 18, 2022
1 parent a390665 commit 15a583d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def start_with_expected_failure(self, name, max_wait_limit=40, custom_config=Non
try:
self.start(name, max_wait_limit, custom_config)
assert False, 'expected startup to fail'
except:
except Exception:
pass

def __getattr__(self, func):
Expand Down
7 changes: 4 additions & 3 deletions features/static_primary.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ Feature: static primary
Given I start postgres0 as static primary
Then postgres0 is a leader after 10 seconds
And there is a non empty initialize key in DCS after 15 seconds
When I issue a PATCH request to http://127.0.0.1:8008/config with {"ttl": 20, "loop_wait": 2, "synchronous_mode": true}
When I issue a PATCH request to http://127.0.0.1:8008/config with {"ttl": 20, "loop_wait": 2}
Then I receive a response code 200
When I start postgres1 with a configured static primary will not boot after 20 seconds
And I start postgres2 with a configured static primary will not boot after 20 seconds
And "sync" key not in DCS after waiting 20 seconds
And "members/postgres1" key not in DCS after waiting 10 seconds
And "members/postgres2" key not in DCS after waiting 10 seconds
And "members/postgres1" is stopped and uninitialized after waiting 10 seconds
# NOTE: no need to wait an additional 10 seconds here.
And "members/postgres2" is stopped and uninitialized after waiting 1 seconds

Scenario: check removing static primary config from dcs allows replica startup
Given I issue a PATCH request to http://127.0.0.1:8008/config with {"static_primary": null}
Expand Down
38 changes: 33 additions & 5 deletions features/steps/static_primary.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
import patroni.psycopg as pg

from behave import step, then
from time import sleep, time
from behave import step
from time import sleep


@step('I start {name:w} as static primary')
Expand All @@ -18,8 +17,37 @@ def start_patroni_as_replica_with_static_primary(context, name, time_limit):
@step('"{name}" key not in DCS after waiting {time_limit:d} seconds')
def check_member_not_present(context, name, time_limit):
sleep(time_limit)
found_value = False
try:
json.loads(context.dcs_ctl.query(name))
res = json.loads(context.dcs_ctl.query(name))
if res is not None:
found_value = True
except Exception:
pass

if found_value:
print("found value under DCS key {}: {}".format(name, res))
assert False, "found value under DCS key {} after {} seconds".format(name, time_limit)
return True


@step('"{name}" is stopped and uninitialized after waiting {time_limit:d} seconds')
def member_is_stopped_and_uninitialized(context, name, time_limit):
sleep(time_limit)
value = None
try:
value = json.loads(context.dcs_ctl.query(name))
print("response from dcs_ctl.query({}): {}".format(name, value))
except Exception:
return
pass

if value is None:
assert False, "context.dcs_ctl.query({}) unexpectedly returned None".format(name)

state = value.get("state")
role = value.get("role")
if state != "stopped":
assert False, "{} has state {}, expected 'stopped', after {} seconds".format(name, state, time_limit)
if role != "uninitialized":
assert False, "{} has role {}, expected 'uninitialized', after {} seconds".format(name, role, time_limit)
return True

0 comments on commit 15a583d

Please sign in to comment.