forked from patroni/patroni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add behavioral tests for static primary feature
- Loading branch information
Showing
6 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Feature: static primary | ||
We should check that static primary behavior is safe | ||
|
||
Scenario: check static primary config in dcs blocks replica from starting | ||
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} | ||
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 | ||
|
||
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} | ||
Then "sync" key in DCS has leader=postgres0 after 20 seconds | ||
And "members/postgres1" key in DCS has state=running after 10 seconds | ||
And "members/postgres2" key in DCS has state=running after 10 seconds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
import patroni.psycopg as pg | ||
|
||
from behave import step, then | ||
from time import sleep, time | ||
|
||
|
||
@step('I start {name:w} as static primary') | ||
def start_patroni_with_static_primary(context, name): | ||
return context.pctl.start(name, custom_config={'bootstrap': {'dcs': {'static_primary': name}}}) | ||
|
||
|
||
@step('I start {name:w} with a configured static primary will not boot after {time_limit:d} seconds') | ||
def start_patroni_as_replica_with_static_primary(context, name, time_limit): | ||
return context.pctl.start_with_expected_failure(name, max_wait_limit=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) | ||
try: | ||
json.loads(context.dcs_ctl.query(name)) | ||
assert False, "found value under DCS key {} after {} seconds".format(name, time_limit) | ||
except Exception: | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters