Skip to content

Commit d467d8c

Browse files
committed
checking after scale to 2 and checking after scale up to 3
1 parent 8382d0d commit d467d8c

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

tests/integration/ha_tests/helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,3 +901,10 @@ async def create_test_data(connection_string):
901901
data = cursor.fetchone()
902902
assert data[0] == "some data"
903903
connection.close()
904+
905+
async def get_last_added_unit(ops_test, app, prev_units):
906+
curr_units = [unit.name for unit in ops_test.model.applications[app].units]
907+
new_unit = list(set(curr_units) - set(prev_units))[0]
908+
for unit in ops_test.model.applications[app].units:
909+
if new_unit == unit.name:
910+
return unit

tests/integration/ha_tests/test_self_healing.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
storage_type,
5555
update_restart_condition,
5656
validate_test_data,
57-
wait_network_restore,
57+
wait_network_restore, get_last_added_unit,
5858
)
5959

6060
logger = logging.getLogger(__name__)
@@ -595,7 +595,7 @@ async def test_deploy_zero_units(ops_test: OpsTest):
595595
except Exception as e:
596596
assert False, f"{e} unit host = http://{unit_ip}:8008, something went wrong"
597597

598-
# Scale the database to one unit.
598+
# Scale up to one unit.
599599
logger.info("scaling database to one unit")
600600
await add_unit_with_storage(ops_test, app=app, storage=primary_storage)
601601
await ops_test.model.wait_for_idle(status="active", timeout=1500)
@@ -607,18 +607,34 @@ async def test_deploy_zero_units(ops_test: OpsTest):
607607
logger.info("check test database data")
608608
await validate_test_data(connection_string)
609609

610-
# Scale the database to three units.
610+
# Scale up to two units.
611611
logger.info("scaling database to two unit")
612+
prev_units = [unit.name for unit in ops_test.model.applications[app].units]
612613
await scale_application(ops_test, application_name=app, count=2)
613-
for unit in ops_test.model.applications[app].units:
614-
if not await unit.is_leader_from_status():
615-
assert await reused_replica_storage(
616-
ops_test, unit_name=unit.name
617-
), "attached storage not properly re-used by Postgresql."
618-
logger.info(f"check test database data of unit name {unit.name}")
619-
connection_string, _ = await get_db_connection(
620-
ops_test, dbname=dbname, is_primary=False, replica_unit_name=unit.name
621-
)
622-
await validate_test_data(connection_string)
614+
unit = await get_last_added_unit(ops_test, app, prev_units)
615+
616+
logger.info(f"check test database data of unit name {unit.name}")
617+
connection_string, _ = await get_db_connection(
618+
ops_test, dbname=dbname, is_primary=False, replica_unit_name=unit.name
619+
)
620+
await validate_test_data(connection_string)
621+
assert await reused_replica_storage(
622+
ops_test, unit_name=unit.name
623+
), "attached storage not properly re-used by Postgresql."
624+
625+
# Scale up to three units.
626+
logger.info("scaling database to three unit")
627+
prev_units = [unit.name for unit in ops_test.model.applications[app].units]
628+
await scale_application(ops_test, application_name=app, count=3)
629+
unit = await get_last_added_unit(ops_test, app, prev_units)
630+
631+
logger.info(f"check test database data of unit name {unit.name}")
632+
connection_string, _ = await get_db_connection(
633+
ops_test, dbname=dbname, is_primary=False, replica_unit_name=unit.name
634+
)
635+
await validate_test_data(connection_string)
636+
assert await reused_replica_storage(
637+
ops_test, unit_name=unit.name
638+
), "attached storage not properly re-used by Postgresql."
623639

624640
await check_writes(ops_test)

0 commit comments

Comments
 (0)