From 6f039532680fd5cc42c81a0c1b357c528f431727 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Wed, 24 Feb 2016 17:12:45 +0100 Subject: [PATCH] Merge basic failover and basic replication scenarios in one feature. --- features/basic_failover.feature | 13 ------------ features/basic_failover.py | 33 ------------------------------ features/basic_replication.feature | 10 +++++++++ features/basic_replication.py | 5 +++++ features/terrain.py | 2 +- 5 files changed, 16 insertions(+), 47 deletions(-) delete mode 100644 features/basic_failover.feature delete mode 100644 features/basic_failover.py diff --git a/features/basic_failover.feature b/features/basic_failover.feature deleted file mode 100644 index 95b7d646..00000000 --- a/features/basic_failover.feature +++ /dev/null @@ -1,13 +0,0 @@ -Feature: basic failover - In order to check that failover works - As observers - We start the primary and the replica, - shut down the primary - and check that the replica assumed the primary role. - -Scenario: check the basic failover - Given basic replication - When I shut down postgres0 - Then postgres1 role is the primary after 10 seconds - When I start postgres0 - Then postgres0 role is the secondary after 10 seconds \ No newline at end of file diff --git a/features/basic_failover.py b/features/basic_failover.py deleted file mode 100644 index 661cfb28..00000000 --- a/features/basic_failover.py +++ /dev/null @@ -1,33 +0,0 @@ -from lettuce import world, steps - -PATRONI_CONFIG = '{}.yml' - - -@steps -class BasicFailoverSteps(object): - - def __init__(self, environ): - self.env = environ - - def basic_replication(self, step): - '''Basic replication''' - step.behave_as(""" - Given I start postgres0 - And I start postgres1 - When I add the table foo to postgres0 - Then table foo is present on postgres1 after 10 seconds - """) - - def start_patroni(self, step, pg_name): - '''I start (\w+)''' - return world.pctl.start_patroni(pg_name) - - def stop_patroni(self, step, pg_name): - '''I shut down (\w+)''' - return world.pctl.stop_patroni(pg_name) - - def check_role(self, step, pg_name, pg_role, max_promotion_timeout): - '''(\w+) role is the (\w+) after (\d+) seconds''' - return world.pctl.check_role_has_changed_to(pg_name, pg_role, timeout=int(max_promotion_timeout)) - -BasicFailoverSteps(world) diff --git a/features/basic_replication.feature b/features/basic_replication.feature index 4306bc10..140e0cf2 100644 --- a/features/basic_replication.feature +++ b/features/basic_replication.feature @@ -4,9 +4,19 @@ Feature: basic replication We start the primary and the replica add a table on the primary and check that it gets replicated to the replica over time. + We stop the primary and check that the replica promotes itself to primary + We start the old primary and check that it rejoins as a replica. Scenario: check replication of a single table Given I start postgres0 And I start postgres1 When I add the table foo to postgres0 Then table foo is present on postgres1 after 10 seconds + + Scenario: check the basic failover + When I shut down postgres0 + Then postgres1 role is the primary after 10 seconds + When I start postgres0 + Then postgres0 role is the secondary after 10 seconds + When I add the table bar to postgres1 + Then table bar is present on postgres1 after 10 seconds \ No newline at end of file diff --git a/features/basic_replication.py b/features/basic_replication.py index d856c6fb..4c26da37 100644 --- a/features/basic_replication.py +++ b/features/basic_replication.py @@ -34,4 +34,9 @@ class BasicReplicationSteps(object): assert False,\ "Table {0} is not present on {1} after {2} seconds".format(table_name, pg_name, max_replication_delay) + def check_role(self, step, pg_name, pg_role, max_promotion_timeout): + '''(\w+) role is the (\w+) after (\d+) seconds''' + return world.pctl.check_role_has_changed_to(pg_name, pg_role, timeout=int(max_promotion_timeout)) + + BasicReplicationSteps(world) diff --git a/features/terrain.py b/features/terrain.py index 3c7a0609..2a9b23cc 100644 --- a/features/terrain.py +++ b/features/terrain.py @@ -224,7 +224,7 @@ def etcd_cleanup(): assert False, "Unable to cleanup etcd: {0}".format(e) -@after.each_scenario +@after.each_feature def cleanup(scenario): patroni_cleanup_all() etcd_cleanup()