Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
load_mysql_test_data,
update_interval,
wait_for_apps_status,
wait_for_unit_status,
)

MYSQL_APP_NAME = "mysql-k8s"
Expand All @@ -30,6 +31,7 @@ def test_deploy_single_unit_cluster(juju: Juju, charm: str) -> None:
config={"profile": "testing"},
resources={"mysql-image": CHARM_METADATA["resources"]["mysql-image"]["upstream-source"]},
num_units=1,
trust=True,
)

logging.info("Wait for applications to become active")
Expand All @@ -51,12 +53,21 @@ def test_crash_during_cluster_setup(juju: Juju, charm: str) -> None:
"""
mysql_primary = get_mysql_primary_unit(juju, MYSQL_APP_NAME)

# NOTE: This is prone to race conditions:
# if the units clear the "waiting" phase too quickly,
# this status function will never activate
Comment on lines +56 to +58
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to leave a comment if we are going to fix the problem here and now.

logging.info("Scaling to 3 units")
juju.add_unit(MYSQL_APP_NAME, num_units=2)
juju.wait(
ready=wait_for_apps_status(jubilant.any_waiting, MYSQL_APP_NAME),
ready=lambda status: any((
*(
wait_for_unit_status(MYSQL_APP_NAME, unit_name, "waiting")(status)
for unit_name in status.get_units(MYSQL_APP_NAME)
),
)),
Comment on lines +62 to +67
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure having any unit in the waiting status is the required condition for this test to validate behavior upon cluster setup failure. There is a reason why this wait condition was initially targeting the application: we need to make sure no unit has actually setup the cluster.

Therefore, I think there are 3 possible ways to achieve this:

  • A) Wait for maintenance status at the app level.
  • B) Wait for maintenance status in all the units.
  • C) Wait for waiting status in all the units.

Given how brief (+ juju-controller dependent) the waiting status is, I would argue A or B are best.

error=jubilant.any_blocked,
timeout=20 * MINUTE_SECS,
successes=1,
)

logging.info("Deleting pod")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def test_build_and_deploy(juju: Juju, charm) -> None:
juju.wait(
ready=lambda status: all((
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}1")
),
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}2", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}2", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}2")
),
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_build_and_deploy(juju: Juju, charm) -> None:
juju.wait(
ready=lambda status: all((
*(
wait_for_unit_status(INTEGRATOR_APP_NAME, unit_name, "blocked")
wait_for_unit_status(INTEGRATOR_APP_NAME, unit_name, "blocked")(status)
for unit_name in status.get_units(INTEGRATOR_APP_NAME)
),
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def test_build_and_deploy(juju: Juju, charm) -> None:
juju.wait(
ready=lambda status: all((
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}1")
),
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}2", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}2", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}2")
),
)),
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_charmed_read_role(juju: Juju):
# wait for relation to be fully removed before adding it again in the following test
jubilant.all_agents_idle(status, f"{INTEGRATOR_APP_NAME}1"),
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}1")
),
)),
Expand Down Expand Up @@ -249,11 +249,11 @@ def test_charmed_dml_role(juju: Juju):
juju.wait(
ready=lambda status: all((
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}1", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}1")
),
*(
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}2", unit_name, "blocked")
wait_for_unit_status(f"{INTEGRATOR_APP_NAME}2", unit_name, "blocked")(status)
for unit_name in status.get_units(f"{INTEGRATOR_APP_NAME}2")
),
)),
Expand Down
Loading