From b0818ab6048966a8dbe623924bfea7b9c80845fe Mon Sep 17 00:00:00 2001 From: Mykola Marzhan Date: Wed, 28 Feb 2024 17:28:06 +0100 Subject: [PATCH] improve SST test --- tests/integration/ha_tests/test_self_healing.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/integration/ha_tests/test_self_healing.py b/tests/integration/ha_tests/test_self_healing.py index 0dcc43be02..71ac8290e1 100644 --- a/tests/integration/ha_tests/test_self_healing.py +++ b/tests/integration/ha_tests/test_self_healing.py @@ -157,7 +157,7 @@ async def test_kill_db_process( await send_signal_to_process(ops_test, primary_name, process, "SIGKILL") async with ops_test.fast_forward(): - await are_writes_increasing(ops_test, primary_name) + await are_writes_increasing(ops_test, down_unit=primary_name) # Verify that the database service got restarted and is ready in the old primary. assert await is_postgresql_ready(ops_test, primary_name) @@ -190,7 +190,7 @@ async def test_freeze_db_process( # considered to trigger a fail-over after primary_start_timeout is changed, and also # when freezing the DB process it take some more time to trigger the fail-over). try: - await are_writes_increasing(ops_test, primary_name) + await are_writes_increasing(ops_test, down_unit=primary_name) # Verify that a new primary gets elected (ie old primary is secondary). for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(3)): @@ -223,7 +223,7 @@ async def test_restart_db_process( await send_signal_to_process(ops_test, primary_name, process, "SIGTERM") async with ops_test.fast_forward(): - await are_writes_increasing(ops_test, primary_name) + await are_writes_increasing(ops_test, down_unit=primary_name) # Verify that the database service got restarted and is ready in the old primary. assert await is_postgresql_ready(ops_test, primary_name) @@ -345,7 +345,7 @@ async def test_forceful_restart_without_data_and_transaction_logs( assert new_primary_name is not None assert new_primary_name != primary_name - await are_writes_increasing(ops_test, primary_name) + await are_writes_increasing(ops_test, down_unit=primary_name) # Change some settings to enable WAL rotation. for unit in ops_test.model.applications[app].units: @@ -369,8 +369,11 @@ async def test_forceful_restart_without_data_and_transaction_logs( # Check that the WAL was correctly rotated. for unit_name in files: assert not files[unit_name].intersection( - new_files + new_files[unit_name] ), "WAL segments weren't correctly rotated" + for file in files[unit_name]: + cmd = f"rm -rf /var/snap/charmed-postgresql/common/var/lib/postgresql/pg_wal/{file}" + run_command_on_unit(ops_test, unit_name, cmd) # Start the systemd service in the old primary. await run_command_on_unit(ops_test, primary_name, "snap start charmed-postgresql.patroni") @@ -428,7 +431,7 @@ async def test_network_cut(ops_test: OpsTest, continuous_writes, primary_start_t async with ops_test.fast_forward(): logger.info("checking whether writes are increasing") - await are_writes_increasing(ops_test, primary_name) + await are_writes_increasing(ops_test, down_unit=primary_name) logger.info("checking whether a new primary was elected") # Verify that a new primary gets elected (ie old primary is secondary). @@ -517,7 +520,7 @@ async def test_network_cut_without_ip_change( async with ops_test.fast_forward(): logger.info("checking whether writes are increasing") - await are_writes_increasing(ops_test, primary_name, use_ip_from_inside=True) + await are_writes_increasing(ops_test, down_unit=primary_name, use_ip_from_inside=True) logger.info("checking whether a new primary was elected") # Verify that a new primary gets elected (ie old primary is secondary).