Skip to content

Commit

Permalink
fixes for network cut tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Oct 21, 2024
1 parent b5479c5 commit f9d781c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions tests/integration/upgrades/test_sharding_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None:
}
await deploy_and_scale_application(ops_test)

await deploy_cluster_components(ops_test, num_units_cluster_config)
await deploy_cluster_components(ops_test, num_units_cluster_config, channel="6/edge")

await ops_test.model.wait_for_idle(
apps=CLUSTER_COMPONENTS,
Expand Down Expand Up @@ -162,7 +162,7 @@ async def test_pre_upgrade_check_failure(ops_test: OpsTest, chaos_mesh) -> None:

non_leader_unit = None
for unit in ops_test.model.applications[SHARD_TWO_APP_NAME].units:
if unit != leader_unit:
if unit.name != leader_unit.name:
non_leader_unit = unit
break

Expand All @@ -175,7 +175,7 @@ async def test_pre_upgrade_check_failure(ops_test: OpsTest, chaos_mesh) -> None:
leader_unit = await backup_helpers.get_leader_unit(ops_test, sharding_component)
action = await leader_unit.run_action("pre-refresh-check")
await action.wait()
assert action.status == "completed", "pre-refresh-check failed, expected to succeed."
assert action.status == "failed", "pre-refresh-check succeeded, expected to fail."

# restore network after test
remove_instance_isolation(ops_test)
Expand Down
16 changes: 13 additions & 3 deletions tests/integration/upgrades/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pytest_operator.plugin import OpsTest

from ..backup_tests import helpers as backup_helpers
from ..ha_tests import helpers as ha_helpers
from ..ha_tests.helpers import (
count_writes,
deploy_and_scale_application,
Expand All @@ -27,6 +28,15 @@
MONGODB_CHARM_NAME = "mongodb-k8s"


@pytest.fixture(scope="module")
def chaos_mesh(ops_test: OpsTest) -> None:
ha_helpers.deploy_chaos_mesh(ops_test.model.info.name)

yield

ha_helpers.destroy_chaos_mesh(ops_test.model.info.name)


@pytest.mark.group(1)
@pytest.mark.abort_on_fail
async def test_build_and_deploy(ops_test: OpsTest):
Expand Down Expand Up @@ -87,7 +97,7 @@ async def test_preflight_check_failure(ops_test: OpsTest, chaos_mesh) -> None:

non_leader_unit = None
for unit in ops_test.model.applications[db_app_name].units:
if unit != leader_unit:
if unit.name != leader_unit.name:
non_leader_unit = unit
break

Expand All @@ -99,12 +109,12 @@ async def test_preflight_check_failure(ops_test: OpsTest, chaos_mesh) -> None:
logger.info("Calling pre-refresh-check")
action = await leader_unit.run_action("pre-refresh-check")
await action.wait()
assert action.status == "completed", "pre-refresh-check failed, expected to succeed."
assert action.status == "failed", "pre-refresh-check succeeded, expected to fail."

# restore network after test
remove_instance_isolation(ops_test)
await ops_test.model.wait_for_idle(
apps=[db_app_name], status="active", timeout=1000, idle_period=30
apps=[db_app_name], status="active", timeout=1000, idle_period=30, raise_on_error=False
)


Expand Down

0 comments on commit f9d781c

Please sign in to comment.